状态活动用户的discord.js自动角色

ttvkxqim  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(278)

我目前正在js中创建一个discord机器人,但我遇到了麻烦,但我不知道它是从哪里来的,有人能帮我吗?

bot.on('presenceUpdate', (oldPresence, newPresence) => {
  const role = newPresence.guild.roles.cache.get("863104096377503754");
  const member = newPresence.member
  const activities = member.user.presence.activities[0];

  if(newPresence.activities[0].state === "hello") {
    return newPresence.member.roles.add(role).catch((e) => console.log(e));
  }
  if(!newPresence.activities[0].state === "hello") {
    return newPresence.member.roles.remove(role).catch((e) => console.log(e));
  }
})

我有这个错误

No debugger available, can not send 'variables'
Uncaught TypeError: Cannot read property 'state' of undefined
TypeError [INVALID_TYPE]: Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes.
    at GuildMemberRoleManager.add (c:\Users\X-trem Info\Desktop\Nouveau dossier (2)\mori - Copie\node_modules\discord.js\src\managers\GuildMemberRoleManager.js:93:15)
    at Client.<anonymous> (c:\Users\X-trem Info\Desktop\Nouveau dossier (2)\mori - Copie\BotMain.js:30:37)
    at Client.emit (<node_internals>/events.js:210:5)
    at PresenceUpdateAction.handle (c:\Users\X-trem Info\Desktop\Nouveau dossier (2)\mori - Copie\node_modules\discord.js\src\client\actions\PresenceUpdate.js:39:19)
    at Object.module.exports [as PRESENCE_UPDATE] (c:\Users\X-trem Info\Desktop\Nouveau dossier (2)\mori - Copie\node_modules\discord.js\src\client\websocket\handlers\PRESENCE_UPDATE.js:4:33)
    at WebSocketManager.handlePacket (c:\Users\X-trem Info\Desktop\Nouveau dossier (2)\mori - Copie\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (c:\Users\X-trem Info\Desktop\Nouveau dossier (2)\mori - Copie\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (c:\Users\X-trem Info\Desktop\Nouveau dossier (2)\mori - Copie\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (c:\Users\X-trem Info\Desktop\Nouveau dossier (2)\mori - Copie\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (events.js:210:5) {stack: 'TypeError [INVALID_TYPE]: Supplied roles is n…2:16)
    at WebSocket.emit (events.js:210:5)', message: 'Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes.', Symbol(code): 'INVALID_TYPE'}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题