繁体   English   中英

Discord.JS 角色创建事件

[英]Discord.JS roleCreate event

client.on("roleCreate", role => {
  const channel = role.guild.channels.cache.find(ch => ch.name === "welcome");
  const embed = new Discord.MessageEmbed()
    .setColor("DEFAULT")
    .setDescription(`A new role has been created\nPermissions List: ${role.permissions}`)
    channel.send(embed)
});

我正在尝试 Discord.JS 文档中的不同事件,但是,当我遇到roleCreate事件时,我尝试了它,当我创建一个新角色时,它可以工作。 但是对于role.permissions ; 我不太清楚为什么会得到[object Object] 我怎么可能解决这个问题?

Discord.JS: v12.2.0

这是因为role.permissions是 object:

https://discord.js.org/#/docs/main/stable/class/Permissions

.toArray()方法与join()结合使用:

client.on("roleCreate", role => {
  const channel = role.guild.channels.cache.find(ch => ch.name === "welcome");
  const perms = role.permissions.toArray().join("\n");
  const embed = new Discord.MessageEmbed()
    .setColor("DEFAULT")
    .setDescription(`A new role has been created\nPermissions List:\n${perms}`)
    channel.send(embed)
});

将其从CREATE_INSTANT_INVITE获取到Create Instant Invite

const perms = role.permissions.toArray().map(e => {
   const words = e.split("_").map(x => x[0] + x.slice(1).toLowerCase());
   return words.join(" ");
}).join("\n");

暂无
暂无

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

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