英文:
Message not defined + The reply to this interaction has already been sent or deferred
问题
机器人在第二次(或更多次)使用命令时发送不同的回复(不是随机的)。
英文:
I was trying to make a code where the bot sends another reply when the bot is used more than one time but for some reson it does not work
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('test')
.setDescription('Ich teste was'),
async execute(interaction) {
const msg = await interaction.reply({
content: "Am Testen",
})
const {reply} = message ?? interaction;
const userId = message.author.id ?? message.member.id ?? interaction.member.id ?? interaction.author.id;
const uses = await db.get(`uses_test_${userId}`) + 1;
await db.set(`uses_test_${userId}`, uses);
if (uses > 1) {
return reply("Du testest nun etwas zum 2x")
}}
}
Bot is sending a different reply (not random) when using the command a second time (or more)
答案1
得分: 1
问题1:message
变量从未声明
问题2:你有两个回复函数
修复方法如下:
- 将
msg
改为interaction.reply()
(缩短) - 移除
{reply}
(不需要这个) - 缩短
userId
(问题1) - 使用
interaction.channel.send()
而不是reply()
(问题2)
示例代码:
async execute(interaction) {
interaction.reply("Am Testen");
const userId = interaction.user.id;
const uses = await db.get(`uses_test_${userId}`) + 1;
await db.set(`uses_test_${userId}`, uses);
if (uses > 1) {
return interaction.channel.send("Du testest nun etwas zum 2x");
}
}
英文:
Issue 1: The message
variable was never declared
Issue 2: You have two reply functions
Here's how to fix:
- Change
msg
to justinteraction.reply()
(Shorten) - Remove
{reply}
(Don't need this) - Shorten
userId
(Issue 1) - Use
interaction.channel.send()
instead ofreply()
(Issue 2)
Example code:
async execute(interaction) {
interaction.reply("Am Testen");
const userId = interaction.user.id;
const uses = await db.get(`uses_test_${userId}`) + 1;
await db.set(`uses_test_${userId}`, uses);
if (uses > 1) {
return interaction.channel.send("Du testest nun etwas zum 2x");
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论