我正在尝试创建一个命令,您可以在其中设置 LFG 角色(LFG = 寻找游戏)。
现在,我需要机器人通过名称查找角色,但它不起作用。我不知道为什么,我尝试了许多其他方法,例如通过 ID 查找角色或以不同的方式构建代码,但什么都没有……代码如下:
collector1.on('collect', () => {
// Si l'utilisateur a cliqué sur 1️⃣ LFG
message.reactions.removeAll();
const embed1 = new MessageEmbed()
.setTitle(
`**--------------------LFG role configuration--------------------**`,
)
.addField(
`You clicked on 1️⃣`,
`Send in the next 30 the name of the new LFG role.`,
true,
)
.addField(
`Missclicked?`,
`Wait 30 seconds for the bot to send a timeout message and try again.`,
true,
);
let filter = (m) => m.author.id === message.author.id;
m.edit(embed1).then(() => {
message.channel
.awaitMessages(filter, {
max: 1,
time: 30000,
errors: ['time'],
})
.then((message) => {
message.reactions.removeAll();
message = message.first();
let role = message.guild.roles.cache.find((r) => r.name === message);
message.channel.send(`Alright, The new lfg role is ${role}!`);
})
.catch((collected) => {
message.channel.send('Timeout.');
});
});
});
另外,我还有第二个问题,即机器人没有删除所有的反应。
答案 0 :(得分:1)
message
不是字符串 - 它是一个 Message
对象。我想你的意思是message.content
let role = message.guild.roles.cache.find((r) => r.name === message.content);
<块引用>
另外,我还有第二个问题,即机器人没有删除所有的反应
也许你的意思是m.reactions.removeAll()
?
答案 1 :(得分:0)
要按名称查找角色,您只需使用
message.guild.roles.find(role => role.name === "Rolename");