【问题标题】:Discord.js bot to react to its own message after user !commandDiscord.js 机器人在用户 !command 之后对自己的消息做出反应
【发布时间】:2021-12-31 14:34:08
【问题描述】:
client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return;

    const { commandName } = interaction;
    const gift = ["Gift 1", "Nothing", "Gift 3", "Nothing", "Gift 5", "Nothing", "Gift 7", "Nothing"]

    const random = Math.floor(Math.random() * gift.length);


    if (commandName === 'gift' && gift[random] === 'Nothing') {
        interaction.reply("No Luck today!");

    } else if (commandName === 'calendar' && gift[random] != 'Nothing') {
        interaction.reply(`Congrats ${interaction.user.username} you won ${gift[random]} !`);
        } 
        
});

我想让机器人对自己的回答“今天不走运!”做出反应或Congrats ${interaction.user.username} you won ${gift[random]} ! 在有人键入 !gift 但交互没有 .react 或 .reaction 之后

知道我该如何做到这一点吗?

【问题讨论】:

    标签: javascript discord discord.js bots


    【解决方案1】:

    CommandInteraction#reply 返回Message 的实例。你可以在那里使用.react

    interaction.reply("No Luck today!").then(m => m.react("emoji"))
    

    对于另一条消息:

    interaction.reply(`Congrats ${interaction.user.username} you won ${gift[random]} !`).then(m => m.react("emoji"))
    

    【讨论】:

    • 谢谢!当成员正在执行 !command 时,我设法让机器人做出反应,而不是对其自己的消息做出反应。现在与您的解决方案完美配合!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 2020-11-07
    • 2021-07-02
    • 2018-12-15
    • 2020-12-05
    • 2019-11-16
    • 1970-01-01
    相关资源
    最近更新 更多