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)
});
I am trying out different events from the Discord.JS Docs, however, when I came across the roleCreate
event, I tried it out and when I create a new role, it works. But for the role.permissions
; I am not quite sure why I'm getting [object Object]
. How could I possibly fix this?
Discord.JS: v12.2.0
That's because role.permissions
is an object:
https://discord.js.org/#/docs/main/stable/class/Permissions
Use the .toArray()
method combined with 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)
});
To get it from CREATE_INSTANT_INVITE
into 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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.