一些我见过/尝试过的东西:
我正试图在我的机器人中创建一个装饰性角色部分。我当前的代码是:
var role = message.guild.roles.find( r => r.name === args[0].join(" "));
member.addRole(role).catch(console.log);
除了没有.join(“”)之外,我以前的代码是相同的。我收到以下错误:
TypeError: Supplied parameter was neither a Role nor a Snowflake.
at GuildMember.addRole (/home/discord/node_modules/discord.js/src/structures/GuildMember.js:454:38)
at Client.client.on.message (/home/discord/Desktop/channel.js:76:10)
at Client.emit (events.js:194:15)
at MessageCreateHandler.handle (/home/discord/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle (/home/discord/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (/home/discord/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (/home/discord/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
at WebSocket.onMessage (/home/discord/node_modules/ws/lib/event-target.js:120:16)
at WebSocket.emit (events.js:189:13)
at Receiver.receiverOnMessage (/home/discord/node_modules/ws/lib/websocket.js:789:20)
Created new role with name test and color 16777215
“创建的新角色”来自创建它的行。请注意,此消息在我的角色创建脚本上以.then发送。我该如何工作?请注意,它可以很好地创建我的角色,只是不能将其添加到执行命令的用户中。使用await无效,因为addRole不是异步函数。
更新:我已经弄清楚该怎么做:使用第二个.then,然后传递role.id。谢谢您的建议!
答案 0 :(得分:0)
是否已定义成员,或者应该是:
message.member.addRole(role).catch(console.log);
已编辑:
尝试使用:
if(!member.roles.has(role.id)) await member.addRole(role.id).catch(console.log);