Discord.js Issue with “.addRole”

北城以北 提交于 2020-03-25 18:54:07

问题


So, I have been having issues setting up a bot that roles a user to a role that includes emoticons. Example:

    const guildMember = message.member;
    guildMember.addRole('<@&439191493169643521>');

I've also tried:

    // content.js
    const guildMember = message.member;
    guildMember.addRole(config.n);

    // config.json
    {
        "n": "🦊Fox"
    }

and also I've tried it without config.json, and just put the raw rank name, but it always doesn't work.

This is the Console:

      (node:15600) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Supplied parameter was neither a Role nor a Snowflake.
      (node:15600) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

回答1:


UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Supplied parameter was neither a Role nor a Snowflake.

Well, 🦊Foxis not a Role Object and is also not a Snowflake (ID).
To add a role you need or a Object or a ID.

If you want to use the ID, you will need to make the role mentionable and then escape the mention \@MyRole, then just copy the ID (it's only the numbers) and use it:

guildMember.addRole('439191493169643521');  

If you want to still go use the name of the role, you can do something like this:

const role = message.guild.roles.find('name', 'MyRole');
guildMember.addRole(role);


来源:https://stackoverflow.com/questions/50055133/discord-js-issue-with-addrole

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!