[英]Nothing happens when the command is run
當我運行 '!hi' 命令時,什么也沒有發生。 終端中也沒有控制台輸出或錯誤。 我在網上查了很多答案,但都沒有奏效。 這是我的代碼:
const Discord = require('discord.js')
const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES'] })
client.on('ready', () => {
console.log('bot is now online!')
})
client.on('messageCreate', (message) => {
if (message.author.bot) return
if (message.channel.type !== 'text') return
let prefix = '!'
let MessageArray = message.content.split(' ')
let cmd = MessageArray[0]
let args = MessageArray.slice(1)
if (!message.content.startsWith(prefix)) return
if (cmd == 'hello') {
message.channel.send('hello')
}
})
client.login(`*******************************************`)
您的命令不起作用,因為cmd等於“!hello”而不是“hello”,要修復它:
let cmd = MessageArray[0].substring(1)
子字符串函數就是為此
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.