NodeJS 我收到错误“交互已被确认”,

bxjv4tth  于 2022-12-22  发布在  Node.js
关注(0)|答案(1)|浏览(90)

我正在创建一个有多个斜杠命令的机器人,无论我做什么,它都会显示错误。
我试过.editReply(),甚至if (interaction.replied = true) {interaction.replied = false}
顺便说一下,我使用ES模块。下面是我的代码:

import { Client, EmbedBuilder, GatewayIntentBits, Routes, SlashCommandBuilder } from 'discord.js';
import {config} from 'dotenv';
import {REST} from '@discordjs/rest'


config();

const client = new Client({intents: [
    GatewayIntentBits.Guilds,
     GatewayIntentBits.GuildMessages,
     GatewayIntentBits.MessageContent,
    ]});

    const token = process.env.token;

    const rest = new REST({version: '10'}).setToken(token)

    const CLIENT_ID = process.env.CLIENT_ID
    

client.on('ready', () => {
    console.log(`${client.user.tag} is ready!`)
})

const embed = new EmbedBuilder()
.setTitle("noobs.")
.setColor("Aqua")
.setDescription("hm.");

client.on('interactionCreate', (interaction) => {

    // if (interaction.commandName == "ping") {
    //     interaction.reply({content: "pong!"})
    
    // }

    if (interaction.options.getString('food') == 'gi') {
interaction.reply({content: 'pong'})

// if (interaction.replied = true) {
//     interaction.replied = false
// }

if (interaction.options.getString('food') != 'gi') {
    interaction.reply({embeds: [embed]})
}


    }

    if (interaction.commandName = "hello") {
        interaction.reply({content: "*gives love* hi"})
    }

  

})

const commands = [
    {
      name: 'ping',
      description: 'Replies with Pong!',
      options: [{
        name: 'food',
        description: 'ur mom',
        type: 3,
        required: true,
      }],
    },

    {
        name: 'hello',
        description: 'Greets you with love.'
    }
  ];
  

async function main() {
try {
console.log("Loading application (/) commands.")
await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands });
console.log('Successfully reloaded application (/) commands.');
} catch (err) {
    console.log(err)
}
}

main();


client.login(token)
pdtvr36n

pdtvr36n1#

您不能仅将interaction.replied设置为false。如果您已回复交互,则只能使用interaction.editReply()interaction.followUp()
因此,尝试检查if(!interaction.replied) {}并将代码放入大括号中。

相关问题