机器人不发送临时消息

诺瓦托原创

我正在制作一个名为 roleinfo 的命令,但是当我希望它按下按钮时,它不会临时发送消息!有谁知道为什么?我已经尝试过interaction.reply,但是在没有deferReply 命令的情况下会出现INTERACTION_ALREADY_REPLIED 错误!


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
                     })
                 }
        })
    }                    
}

在interactionCreate这不可能是问题,记住我的bot总是有回复错误,所以我总是使用followUp

火马里奥211

在按钮按下事件中,您没有调用函数i.deferUpdate这很可能表明交互失败,我建议首先通过调用函数来解决这个问题,你可以通过();在最后添加来做到这一点,这意味着它会是:i.deferUpdate();.

其次,消息没有被临时发送的原因是由于您使用m.reply,您可以再次替换它interaction.followUp,或者替换m.replyi.reply和删除i.deferUpdate();以能够使消息作为临时发送。

例子:

i.deferUpdate();
m.reply({ // Object passed here

i.reply({ // Object passed here

如果我在此答案中犯了错误,请回复,以便我可以编辑修复。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章