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

我有一个机器人,如果您在非命令通道中使用命令,它会发送一条消息,它会告诉您仅在正确的通道中使用命令,但我希望它不会影响具有员工角色的人员,这是我得到的代码这个错误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


慕雪6442864
浏览 74回答 2
2回答

qq_笑_17

如果有人发现这个并正在寻找我使用过&nbsp;let allowedRole = message.guild.roles.cache.find(r => r.name === "Staff");&nbsp;并且对我有用的答案。

江户川乱折腾

您可以尝试这样的操作,以允许具有特定角色的成员使用您的命令:let allowedRole = message.guild.roles.find("name", "Staff");if (message.member.roles.has(allowedRole.id) {&nbsp; &nbsp; // allowed access to command} else { //aka members who arent staff&nbsp;&nbsp; &nbsp;// not allowed access}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript