我第一次在不和谐js和我的测试命令不工作的不和谐机器人



这是我的代码"命令不起作用。我试着看了YouTube上的教程。这是我第一次尝试做这样的事情。我所有的代码经验都来自于简单的python代码。所以如果你有任何视频解释这个,请发送

const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions, Message } = require(`discord.js`);
const prefix = '>';
const client = new Client({
intents: [
32767
]
});
client.on("ready", () => {
console.log("botong is online!")
client.user.setPresence({
status: 'online',
activity: {
name: 'status',
type: 'ActivityType.Playing'
}
});
});
client.on("messageCreate", (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
//message array
const messageArray = message.content.split(" ");
const argument = messageArray.slice(1);
const cmd = messageArray[0];
//commands
//test commands
if (commands === 'test') {
message.channel.send("Bot is working!")
}
})
client.login("MY TOKEN");

试着运行这个,但是什么都没有发生,它应该在我的不和谐服务器上发送一条消息说"Bot正在工作">

所以如果你有任何视频解释这个,请发送

这是一篇来自Codeacademy的文章,解释了如何创建一个简单的Discord bot。https://www.codecademy.com/article/christine_yang/build-a-discord-bot-with-node-js测试消息没有出现的原因:消息从未被发送,因为您没有定义commands,所以它显然永远不会是'test'

if (commands === 'test') {
message.channel.send("Bot is working!")
}

编辑:这是文章中的一个代码示例,每当有人发送"Hello"在那里。

client.on('messageCreate', msg => {
// You can view the msg object here with console.log(msg)
if (msg.content === 'Hello') {
msg.reply(`Hello ${msg.author.username}`);
}
});

最新更新