node.js - 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');
解决方案
推荐阅读
- jquery - 未捕获的 SyntaxError:JQuery UI Datepicker 中分配的左侧无效
- javascript - Leaflet-Routing-Machine:TypeError:无法读取未定义的属性“getSize”
- python - 通过 selenium 获取此元素属性
- c# - 使用 C# 和 html 将多个图像添加到 .NetCore 中的表
- ssl - 如何解决“NSS 错误 -12276 (SSL_ERROR_BAD_CERT_DOMAIN)”
- python - 遇到另一个字母时分裂
- python - 使用循环根据在其他列行中找到的内容在 python 中填充新列的行
- ruby-on-rails - 使用 rails 形式的参数
- arrays - C 语言 - 读取 .csv 文件,搜索特定值时出现问题
- r - 基于另一个矩阵修改矩阵值而不使用循环或应用函数