我目前正在學習使用 node.js 撰寫 discordbots 代碼。出于某種原因,機器人上線但對我編碼的命令沒有反應。為了測驗原因,我什至從教程中獲取了解決方案,但仍然是同樣的問題。有人知道解決方案嗎?
const client = new Discord.Client();
const prefix = '-';
client.once('ready', () => {
console.log('BOT ist online');
});
client.on('Message', (message) => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ /);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');}
else if(command == 'youtube'){
message.channel.send('TEST');}
});
client.login('Here goes the token');
uj5u.com熱心網友回復:
這是一個小修復,所以如果可以,我只會發表評論,但我還不能。
你在哪里做:
client.on(‘Message’, …)
它應該是這樣的訊息中的小寫“m”:
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/355927.html
標籤:javascript 节点.js 不和谐
上一篇:類中的打字稿外部回呼系結
