const {
Client,
GatewayIntentBits,
MessageEmbed,
Partials,
SlashCommandBuilder,
ButtonBuilder,
ButtonStyle,
} = require("discord.js");
const prefix = '!';
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages,],
partials: [Partials.Channel, Partials.Message],
});
client.on("message", msg => {
if (msg.author.bot || !msg.content.startsWith(prefix)) return;
const args = msg.content.slice(prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
// Обработка команд
if (cmd === "ping") {
const pingTime = Date.now() - msg.createdTimestamp;
msg.reply(`Pong! Latency is ${pingTime}ms`);
}
});
client.login(config.BOT_TOKEN);
字符串
代码看起来很简单,它可以在线运行,“/”命令可以工作,但是所有与前缀命令相关的命令都不工作。我不知道原因是什么,我已经尝试了很多代码选项,但是没有任何帮助。错误在哪里?
1条答案
按热度按时间bhmjp9jg1#
如果您希望bot响应前缀,则必须在示例化新客户端时将
MessageContent
Intent添加到Intent中。示例:字符串
不要忘记在developer portal中也启用此选项(Here是一个小教程。