繁体   English   中英

使用 discord.js 创建角色

[英]Creating roles with discord.js

我已经在网上尝试了几乎所有的代码片段,当我尝试它们时,我总是得到一个错误,上面写着ReferenceError: guild is not defined.

case 'setup':
if (msg.member.roles.cache.find(r => r.name === "role")) return msg.reply('bot is already setup')
guild.roles.create({
  data: {
    name: 'role',
    color: 'GREY',
  },
  reason: 'idfk',
})
  .then(console.log)
  .catch(console.error);
break;

错误很明显,您需要定义guild ,或者在这种情况下,说明您要在哪个guild中创建role ,即msg.guild ,即消息发送到的guild

case 'setup':
if (msg.member.roles.cache.find(r => r.name === "role")) return msg.reply('bot is already setup')
msg.guild.roles.create({
  data: {
    name: 'role',
    color: 'GREY',
  },
  reason: 'idfk',
})
  .then(console.log)
  .catch(console.error);
break;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM