簡體   English   中英

Discord.js V12 如何在消息上添加角色?

[英]Discord.js V12 how can add a role on message?

我想在這條消息上添加一個角色,但它給了我錯誤“成員未確定”

   if (message.content === "diocane"){
   message.reply('Now you get a warn');
   member.roles.add('731217864446705714');
   }
   })
member is not defined
    at Client.<anonymous> (C:\Users\lucad\Desktop\Discord Bot\index.js:156:5)
    at Client.emit (events.js:327:22)
    at MessageCreateAction.handle (C:\Users\lucad\Desktop\Discord Bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at WebSocketManager.handlePacket (C:\Users\lucad\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
    at WebSocketShard.onPacket (C:\Users\lucad\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
    at WebSocketShard.onMessage (C:\Users\lucad\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
    at WebSocket.onMessage (C:\Users\lucad\Desktop\Discord Bot\node_modules\ws\lib\event-target.js:125:16)
    at WebSocket.emit (events.js:315:20)
    at Receiver.receiverOnMessage (C:\Users\lucad\Desktop\Discord Bot\node_modules\ws\lib\websocket.js:800:20)
(node:7892) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7892) [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.

你還沒有將成員定義為任何人,所以你會這樣做:

let member = message.author

或者干脆:

message.author.roles.add(`731217864446705714`)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM