问题
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, 🦊Fox
is 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