Вот оно.
Во-первых, имейте в виду, что есть 2 типа смуты раздора. Юникод один, обычные эмодзи, вроде ➡
. И смайлики гильдии, которые вы добавляете на сервер.
Первый представлен только именем юникода, а второй имеет идентификатор и другие различия (см. Emoji и Реакция сообщения )
При этом я использовал имя смайлика в массиве emojiname
. Затем я немного изменил код, чтобы принимать и смайлики юникода и гильдии.
Остальной код был хорош. Обязательно используйте ===
вместо ==
, за исключением случаев, когда вы действительно хотите принять термин "ложный".
демо GIF
// ➡ is an ascii emoji
// lina is a guild emoji
var emojiname = ['➡', 'lina'];
var rolename=["➡ Notifications", "lina supporter"];
client.on('message', msg => {
if(msg.content.startsWith('reaction') && (msg.channel.name.toLowerCase() === 'information')) {
for (let n in emojiname){
let emoji = msg.guild.emojis.find(r => r.name === emojiname[n]);
if (emoji === null) {
emoji = emojiname[n];
}
msg.react(emoji);
}
}
});
client.on("messageReactionAdd",(reaction,user)=>{
if (!user) { return; }
if (user.bot) { return; }
if (reaction.message.channel.name.toLowerCase() !== 'information') { return; }
for(let n in emojiname){
if(reaction.emoji.name === emojiname[n]){
let role = reaction.message.guild.roles.find(r => r.name === rolename[n]);
reaction.message.guild.member(user).addRole(role).catch(console.error);
}
}
});
client.on("messageReactionRemove",(reaction,user)=>{
if(!user) { return; }
if(user.bot) { return; }
if (reaction.message.channel.name.toLowerCase() !== 'information') { return; }
for(let n in emojiname){
if(reaction.emoji.name === emojiname[n]){
let role = reaction.message.guild.roles.find(r => r.name == rolename[n]);
reaction.message.guild.member(user).removeRole(role).catch(console.error);
}
}
});