【问题标题】:Why does my discord bot not add roles properly?为什么我的不和谐机器人无法正确添加角色?
【发布时间】:2020-10-31 21:18:11
【问题描述】:

我正在尝试制作一个机器人,当有人键入 !joinchoiceOutOfVariousRoles 时,它会在服务器中添加一个角色。我目前正在使用 discord 版本 12。我的错误消息是:

fn = fn.bind(thisArg);

虽然尝试了各种技术,但我无法让代码工作。

const Discord = require('discord.js');
const client= new Discord.Client();
const token = process.env.DISCORD_BOT_SECRET




client.on('ready', () => {
    console.log("I'm in");
    console.log(client.user.username);
});


client.on('message', msg  => {  
    if (msg.content.toLowerCase().startsWith("!join"))
    {
        var args = msg.content.toLowerCase().split(" ")
        console.log(args)
        if (args[1] === 'sullen') 
        {
            msg.channel.send('You have successfully joined Sullen!')
            const sullenRole = msg.guild.roles.cache.find('name','Sullen')
            msg.member.addRole(role.id)
            
        }
        
    }
});



client.login(token)

**编辑:修复了每个人都在说的问题,我现在需要做的就是更新权限,(我的朋友必须这样做,因为它不是我的机器人),我应该一切都好。谢谢大家! :D

【问题讨论】:

  • 你的代码的第一个问题是你是mixing v11 and v12 code
  • 请详细说明一下?
  • 您只能在 v12 中使用 cache,而 addRole 是 v11 语法。你有什么版本?
  • 现在我使用的是 12.4.1 版本。
  • 另外,您对Collection.prototype.find() 使用了错误的语法。请检查我链接的页面。

标签: discord discord.js


【解决方案1】:

discord.js 非常频繁地引入重大更改,v12 也不例外。您需要确保找到最新的代码,否则它将无法正常工作。 GuildMember#addRole 被移动到GuildMemberRoleManager#add,这意味着你必须使用msg.member.roles.add(sullenRole)

【讨论】:

    猜你喜欢
    • 2021-08-03
    • 2017-10-18
    • 2021-01-15
    • 1970-01-01
    • 2022-12-03
    • 2018-08-11
    • 1970-01-01
    • 2019-02-02
    • 2020-12-15
    相关资源
    最近更新 更多