无法通过名称找到角色

Unable to find a role by its name

我正在尝试创建一个命令,您可以在其中设置 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.');
      });
  });
});

此外,我还有第二个问题,即机器人没有删除所有反应。

要按名称查找角色,您只需使用

message.guild.roles.find(role => role.name === "Rolename");

message 不是字符串 - 它是 Message 对象。我想你的意思是 message.content

let role = message.guild.roles.cache.find((r) => r.name === message.content);

Also, I have a second problem which is the bot doesn't remove all the reactions

也许你的意思是 m.reactions.removeAll()