Discord.js 机器人在用户 !command 后对自己的消息做出反应
Discord.js bot to react to its own message after user !command
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]} !`);
}
});
我想让机器人在有人输入 !gift 但交互没有 .react 或 .reaction[=13= 后对自己的答案 'No luck today!' 或 Congrats ${interaction.user.username} you won ${gift[random]} !
做出反应]
知道如何做到这一点吗?
CommandInteraction#reply
returns 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"))
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]} !`);
}
});
我想让机器人在有人输入 !gift 但交互没有 .react 或 .reaction[=13= 后对自己的答案 'No luck today!' 或 Congrats ${interaction.user.username} you won ${gift[random]} !
做出反应]
知道如何做到这一点吗?
CommandInteraction#reply
returns 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"))