【问题标题】:Editing a bot's message based on a reaction根据反应编辑机器人的消息
【发布时间】:2020-09-24 18:39:46
【问题描述】:

我刚开始使用 javascript 尝试使用 discord.js 设置一个不和谐机器人。我想使用这个机器人作为组织“文明 6”组的“简单”方式。因此,人们只需点击“+”反应即可将姓名添加到列表中

const Discord = require('discord.js');
const client = new Discord.Client();

然后是前缀和令牌等...

client.on('message', message=>{    
    let args = message.content.slice(PREFIX.length).split(" ");

...检查命令的东西

然后是实际的命令

switch(args[0]){
        case 'civ':
            const civ = new Discord.MessageEmbed()
            .setTitle('Civ 6 Group')
            .addField('Players Joined', message.author.username, true)
            .setColor(0x00FFFF)
            .setThumbnail(message.author.avatarURL)
            .setFooter('Bot created by Plasy#0274')
            message.channel.send(civ).then(sentEmbed => {
                sentEmbed.react('718418753137803367');                             
                sentEmbed.react('718421670276235344');
            if (Discord.user.sentEmbed.react('718418753137803367'))then (message.channel.send('yes'))

            })
        break;

我可以做些什么来使这项工作如我所愿?我非常卡住,所以我很感激任何帮助:)

【问题讨论】:

    标签: javascript node.js bots discord discord.js


    【解决方案1】:

    从这部分开始:

    message.channel.send(civ).then(sentEmbed => {
                    sentEmbed.react('718418753137803367');                             
                    sentEmbed.react('718421670276235344');
    

    您需要在消息上创建一个反应收集器。

    根据docs,您可以这样制作:

    // Create a reaction collector
    const filter = (reaction, user) => (reaction.emoji.id === '718418753137803367' || reaction.emoji.id === '718421670276235344') && user.id !== client.user.id;
    
    const collector = message.createReactionCollector(filter, { time: 15000 });
    collector.on('collect', (r, user) => {
        console.log(`Collected ${r.emoji.name}`);
        if (r.emoji.id === '718418753137803367') {
            // Do something with reaction 1
        }
        else if (r.emoji.id === '718421670276235344') {
            // Do something with reaction 2
        }
    });
    // This is optional.
    collector.on('end', collected => console.log(`Collected ${collected.size} items`));
    

    如果我很好地理解了您的问题,那么您可能还想将新名称添加到您的嵌入中。假设您只有一个字段,您可以通过将此代码放入“do something with...”部分来实现这一点:

    sentEmbed.fields[0].value += `, ${user.username} *(Team 1 or 2)*`;
    

    我希望这会让您走上正确的道路,如果您有任何其他问题,请务必在下方发表评论

    【讨论】:

    猜你喜欢
    • 2020-11-17
    • 2021-05-08
    • 2020-06-13
    • 2020-09-08
    • 2020-09-28
    • 2020-10-10
    • 2021-09-13
    • 2020-07-28
    • 2019-09-11
    相关资源
    最近更新 更多