消息未定义 + 对此交互的回复已经发送或推迟

huangapple go评论66阅读模式
英文:

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:你有两个回复函数

修复方法如下:

  1. msg 改为 interaction.reply()(缩短)
  2. 移除 {reply}(不需要这个)
  3. 缩短 userId(问题1)
  4. 使用 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:

  1. Change msg to just interaction.reply() (Shorten)
  2. Remove {reply} (Don't need this)
  3. Shorten userId (Issue 1)
  4. Use interaction.channel.send() instead of reply() (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");
    }
}

huangapple
  • 本文由 发表于 2023年1月10日 22:52:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75071750.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定