[英]Can't get role with discord.js
我正在使用discord.js
開發一個 Discord 機器人。 下面的代碼應該給選定的用戶一個特定的角色。
const roleTag = message.guild.roles.cache.find(role => role.name === '<role name>');
const member = message.mentions.members.first();
member.roles.add(role);
但是每次我收到錯誤消息時說:
TypeError: Cannot read property 'roles' of undefined
注意:message對象沒有問題(我查過了)
你在哪里得到錯誤,在 add 函數或定義 roleTag 中? 順便說一句,您正在機器人添加定義的角色,您正在添加角色並將其命名為roleTag
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.