I'm making a command called roleinfo, but when I want it to press the buttons it doesn't send the message in ephemeral! Does anyone know why? I've already tried the interaction.reply but the INTERACTION_ALREADY_REPLIED error comes up without the command having a deferReply!
const { MessageEmbed, MessageActionRow, MessageButton } = require("discord.js");
const moment = require("moment");
moment.locale("pt-BR");
module.exports = {
name: "roleteste",
description: "Obtenha informações de um cargo",
options: [
{
name: "role",
type: "ROLE",
description: "O cargo que você deseja obter as informações !",
required: true,
},
],
run: async (client, interaction, args) => {
const role = interaction.guild.roles.cache.get(args[0]);
const permissions = {
"ADMINISTRATOR": "Administrador",
"VIEW_AUDIT_LOG": "Ver Registro de Auditoria",
"VIEW_GUILD_INSIGHTS": "Exibir insights do servidor",
"MANAGE_GUILD": "Gerenciar Servidor",
"MANAGE_ROLES": "Gerenciar Cargos",
"MANAGE_CHANNELS": "Gerenciar Canais",
"KICK_MEMBERS": "Expulsar Membros",
"BAN_MEMBERS": "Banir Membros",
"CREATE_INSTANT_INVITE": "Criar convite",
"CHANGE_NICKNAME": "Mudar apelido",
"MANAGE_NICKNAMES": "Gerenciar apelidos",
"MANAGE_EMOJIS": "Gerenciar Emojis",
"MANAGE_WEBHOOKS": "Gerenciar webhooks",
"VIEW_CHANNEL": "Ler canais de texto e ver canais de voz",
"SEND_MESSAGES": "Enviar mensagens",
"SEND_TTS_MESSAGES": "Enviar mensagens TTS",
"MANAGE_MESSAGES": "Gerenciar mensagens",
"EMBED_LINKS": "Embed Links",
"ATTACH_FILES": "Anexar arquivos",
"READ_MESSAGE_HISTORY": "Leia o histórico da mensagem",
"MENTION_EVERYONE": "Mencione @everyone, @here e Todos os cargos",
"USE_EXTERNAL_EMOJIS": "Usar Emojis Externos",
"ADD_REACTIONS": "Adicionar Reações",
"CONNECT": "Conectar",
"SPEAK": "Falar",
"STREAM": "Video",
"MUTE_MEMBERS": "Mutar Membros",
"DEAFEN_MEMBERS": "Membros surdos",
"MOVE_MEMBERS": "Mover membros",
"USE_VAD": "Usar atividade de voz",
"PRIORITY_SPEAKER": "Orador prioritário"
}
const yesno = {
true: '`Sim`',
false: '`Não`'
}
const rolePermissions = role.permissions.toArray();
const finalPermissions = [];
for (const permission in permissions) {
if (rolePermissions.includes(permission)) finalPermissions.push(`${client.emoji.success} ${permissions[permission]}`);
else finalPermissions.push(`${client.emoji.fail} ${permissions[permission]}`);
}
const position = `\`${interaction.guild.roles.cache.size - role.position}°\``;
const embed = new MessageEmbed()
.setTitle(`${role.name}`)
.addField(`${client.emoji.id} ID`, `\`${role.id}\``, true)
.addField(`${client.emoji.trophy} Posição`, `${position}`, true)
.addField(`${client.emoji.ping} Mencionável`, yesno[role.mentionable], true)
.addField(`${client.emoji.bot} Cargo de bot`, yesno[role.managed], true)
.addField(`${client.emoji.on} Visível`, yesno[role.hoist], true)
.addField(`${client.emoji.rcolor} Cor`, `\`${role.hexColor.toUpperCase()}\``, true)
.addField(`${client.emoji.calendar} Data de criação`, `${moment(role.createdAt).format('LLL')}(${moment(role.createdAt).startOf('day').fromNow()})`, true)
.setColor(`${role.hexColor.toUpperCase()}`)
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setLabel(`Permissões`)
.setEmoji(`${client.emoji.perms}`)
.setCustomId('perms') .setStyle('SECONDARY')
);
const m = await interaction.followUp({ embeds: [embed], components: [row], fetchReply: true })
const iFilter = i => i.user.id === interaction.user.id;
const collector = m.createMessageComponentCollector({ filter: iFilter, time: 10 * 60000 });
collector.on('collect', async(i) => {
switch (i.customId) {
case `perms`:
i.deferUpdate
m.reply({
embeds: [new MessageEmbed()
.setTitle(`${client.emoji.perms} Permissões`)
.setDescription(`${finalPermissions.join('\n')}`)
], ephemeral: true
})
}
})
}
}
In the interactionCreate it can't be the problem, remembering that my bot always had the reply error, so I always used the followUp
Within the button press event, you didn't call the function i.deferUpdate
. Which would most likely state that the interaction failed, I would advise fixing this first by calling the function, you can do this by adding ();
at the end, meaning it would be this: i.deferUpdate();
.
Secondly, the reason why the message isn't being sent ephemerally is due to you using m.reply
, you could instead replace it with interaction.followUp
again, or replace m.reply
with i.reply
and remove i.deferUpdate();
to be able to have the message be sent as ephemeral.
Example:
i.deferUpdate();
m.reply({ // Object passed here
to
i.reply({ // Object passed here
If there is an error I made in this answer, reply so I can edit the fix.