首页 > 解决方案 > Discord JS 命令不发送/响应命令

问题描述

我在 discord.js 中编写了一个不和谐的机器人。我正在尝试实现一些基本命令。

我的问题:每次我尝试运行命令时,机器人都没有响应。有谁能够帮我?

这是我的代码:

const { Client, Intents } = require('discord.js');

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

client.once('ready', () => {
    console.log('Ready!');
});

client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return;

    const { commandName } = interaction;

    if (commandName === 'ping') {
        await interaction.reply('Pong!');
    } else if (commandName === 'beep') {
        await interaction.reply('Boop!');
    } else if (commandName === 'server') {
        await interaction.reply(`Server name: ${interaction.guild.name}\nTotal members: 
${interaction.guild.memberCount}`);
    } else if (commandName === 'user-info') {
        await interaction.reply(`Your username: ${interaction.user.username}\nYour ID: 
${interaction.user.id}`);
    }
});


client.login('MY TOKEN');

标签: node.jsdiscorddiscord.js

解决方案


推荐阅读