Discord.js - 引用错误:成员未定义

问题描述 投票:0回答:1

我遇到了一些问题,我正试图添加一个名为Simon Says Player的角色,有人能帮帮我吗?

bot.on('message', message => {

    let args = message.content.substring(PREFIX.length).split(" ");

    switch (args[0]) {
        case 'join':

            let person = message.guild.member

            if (!person) {
                return message.reply('Couldn`t find the user!');
            }

            let mainRole = (role => role.name === "Simon Says Player");

            member.addRole(mainRole.id);

            message.channel.send('Successfully Entered The Game!!')

            break;
    }
})
javascript node.js discord discord.js roles
1个回答
0
投票

member 其实是 undefined你没有说明预期的功能,但在我看来,你是想给发送了 join 命令。

bot.on('message', message => {

  let args = message.content.substring(PREFIX.length).split(" ");

  switch (args[0]) {
    case 'join':

      let person = message.guild.member

      if (!person) {
        return message.reply('Couldn`t find the user!');
      }

      let mainRole = message.guild.roles.cache.find(role => role.name === "Simon Says Player");

      message.member.roles.add(mainRole.id);

      message.channel.send('Successfully Entered The Game!!')

      break;
  }
})

0
投票

试试 message.member.addRole(mainRole.id) 而不是 member.addRole(mainRole.id)

这在你的例子中应该是有效的。

    switch (args[0]) {
        case 'join':

                let person = message.member

                if (!person) {
                    return message.reply('Couldn`t find the user!');
                }

                let mainRole = message.guild.roles.cache.find(role => role.name === "Simon Says Player");
                message.member.roles.add(mainRole);


                message.channel.send('Successfully Entered The Game!!')

            break;
    }
© www.soinside.com 2019 - 2024. All rights reserved.