'Button issues at discord.js
Well I'm trying to make an avatar config command where it displays the available roles they have to change avatar embed so member can change it by buttons, but the issue is I can't send the buttons based in their roles. I read discord docs but I found nothing. I was able to make a function to replace the roles by string inside an embed and I thought I'd be able to make it with buttons but I think I was wrong.
const Discord = require("discord.js");
function getRoles() {
let role = message.member.roles.cache
let text = ""
if (role.get("staff_role_id")) text += "Staff\n";
if (role.get("active_member_role_id")) text += "Active Member\n";
if (role.get("member_role_id")) text += "Member\n";
roles = `**${text}**`;
return roles;
}
const embed = new Discord.MessageEmbed()
.setDescription(`${getRoles(message.member.roles.cache.map(x => x.id).join(`\n`))}`)
let row = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId(`staff`)
.setStyle(`SECONDARY`)
.setLabel(`Staff`)
)
let row1 = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId(`active_member`)
.setStyle(`SECONDARY`)
.setLabel(`Active Member`)
)
let row2 = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId(`Member`)
.setStyle(`SECONDARY`)
.setLabel(`Membro Stars`)
)
function getRoles() {
let button = ""
if (message.member.roles.cache.get("staff_role_id")) {
button += row
}
if (message.member.roles.cache.get("active_member_role_id")) {
button += row1
}
if (message.member.roles.cache.get("member_role_id")) {
button += row2
}
buttons = button
return buttons;
}
message.channel.send({ embeds: [embed], components: [getRoles] })
Thank you for the help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
