任何操作,除了发送消息,在我的收集器 discordjs 中都不起作用

Posted

技术标签:

【中文标题】任何操作,除了发送消息,在我的收集器 discordjs 中都不起作用【英文标题】:Any action, except send messages, doesn't work in my collector, discordjs 【发布时间】:2022-01-23 07:57:57 【问题描述】:

我有这个命令:

if(prefix&&comando === 'gender'||prefix&&comando === 'pronome')
        const embed = new MessageEmbed()
            .setColor(config.embed_default_color)
            .setTitle('Altere o seu pronome!')
            .setDescription('Quando mudá-lo, eu vou te tratar pelo pronome selecionado.')
            .addField('Selecione uma opção abaixo.', '- - - - - - - -');
        const row = new MessageActionRow()
            .addComponents(
                new MessageSelectMenu()
                    .setCustomId('select')
                    .setPlaceholder('Nothing selected')
                    .addOptions([
                        
                            label: 'Pronome masculino',
                            value: 'men',
                            emoji: '????'
                        ,
                        
                            label: 'Pronome feminino',
                            value: 'woman',
                            emoji: '????'
                        ,
                        
                            label: 'Pronome indefinido',
                            value: 'indef',
                            emoji: '????'
                        ,
                    ]),
            );
        await message.reply( embeds: [embed], components: [row] ).then(msg => 
            const filtro = (interaction) =>
            interaction.isSelectMenu()
            const coletor = msg.createMessageComponentCollector(
                filtro
            );
            coletor.on('collect', async (collected) => 
                let gn = collected.values[0]
                collected.deferUpdate()
                if(gn==='men')
                    msg.delete();
                    await message.channel.send(`$mention **| ✅ Pronome alterado!**\nPronome atualizado para o masculino, Ele/dele.`);
                    gender = 'o';
                
                else if(gn==='woman')
                    msg.delete();
                    await message.channel.send(`$mention **| ✅ Pronome alterado!**\nPronome atualizado para o feminino, Ela/dela.`);
                    gender = 'a';
                
                else if(gn==='men')
                    msg.delete();
                    await message.channel.send(`$mention **| ✅ Pronome alterado!**\nPronome atualizado para indefinido.`);
                    gender = 'x';
                
            )
        )
    

在收集器中(在 if 块上),我有一些操作,因为当用户在下拉菜单中选择一个选项时,会发送消息,但我不能在那里更改任何变量值。 存在一种方法来做到这一点?我真的需要那个。谢谢!

【问题讨论】:

【参考方案1】:

尝试关注这个guide,很完整

下面是一个例子:



const  MessageActionRow, MessageSelectMenu  = require('discord.js');

    client.on('interactionCreate', async interaction => 
        if (!interaction.isCommand()) return;

        if (interaction.commandName === 'MenuOptions') 
            const row = new MessageActionRow()
                .addComponents(
                    new MessageSelectMenu()
                        .setCustomId('select')
                        .setPlaceholder('Nothing selected')
                        .setMinValues(2)
                        .setMaxValues(3)
                        .addOptions([
                            
                                label: 'Select me',
                                description: 'This is a description',
                                value: 'first_option',
                            ,
                            
                                label: 'You can select me too',
                                description: 'This is also a description',
                                value: 'second_option',
                            ,
                            
                                label: 'I am also an option',
                                description: 'This is a description as well',
                                value: 'third_option',
                            ,
                        ]),
                );

            await interaction.reply( content: 'Example!!!!!!!!', components: [row] );
        
    );

【讨论】:

以上是关于任何操作,除了发送消息,在我的收集器 discordjs 中都不起作用的主要内容,如果未能解决你的问题,请参考以下文章

lastmessageID 始终为空,除了我

createReactionCollector 在 discord.js 中不起作用

Discord.py 重新上传图片

Cast SDK 中消息的最大大小是多少?

配置 Zipkin 以跟踪 AWS SQS 消息?

在我的应用程序中发送短信