亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使只有具有特定角色的人才能使用命令。在discord.js v12+ 中

使只有具有特定角色的人才能使用命令。在discord.js v12+ 中

慕雪6442864 2023-10-14 09:48:36
我有一個機器人,如果您在非命令通道中使用命令,它會發送一條消息,它會告訴您僅在正確的通道中使用命令,但我希望它不會影響具有員工角色的人員,這是我得到的代碼這個錯誤TypeError: Cannot read property 'roles' of null 我的代碼:client.on('message', message => {if(!message.member.roles.cache.has(784236433975541771)) {  if (message.content.startsWith("-")) {  if (message.channel.id === '759066524605612108') return;  if (message.channel.id === '775035651640918067') return;  if (message.channel.id === '777287305580511262') return;    message.channel.send('You have been pinged in the <#759066524605612108> channel with the results to your command. Please only use commands there.');  }else  if (message.content.startsWith("!")) {  if (message.channel.id === '759066524605612108') return;  if (message.channel.id === '775035651640918067') return;  if (message.channel.id === '777287305580511262') return;    message.channel.send('Rank has been disabled in this channel. Please only use commands in the <#759066524605612108> channel.');  }}});我正在嘗試這樣做是discord.js v12
查看完整描述

2 回答

?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

如果有人發現這個并正在尋找我使用過 let allowedRole = message.guild.roles.cache.find(r => r.name === "Staff"); 并且對我有用的答案。



查看完整回答
反對 回復 2023-10-14
?
江戶川亂折騰

TA貢獻1851條經驗 獲得超5個贊

您可以嘗試這樣的操作,以允許具有特定角色的成員使用您的命令:


let allowedRole = message.guild.roles.find("name", "Staff");

if (message.member.roles.has(allowedRole.id) {

    // allowed access to command

} else { //aka members who arent staff 

   // not allowed access

}


查看完整回答
反對 回復 2023-10-14
  • 2 回答
  • 0 關注
  • 146 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號