【发布时间】:2021-12-06 09:41:51
【问题描述】:
我用一个简单的“ping”命令创建了一个小型命令处理程序。但是,尝试访问 message.channel 显示未定义。这是为什么呢?
./index.js
//Discord, fs, prefix, client etc. declarations
client.commands = new Collection()
const files = fs.readdirSync("./commands").filter(file => file.endsWith(".js")
for (const file of files) {
const command = require(`./commands/${file}`)
client.commands.set(command.name, command)
}
client.on("messageCreate", message => {
const [command, ...args] = message.content.slice(prefix.length).split(/ +/g)
if (client.commands.has(command) {
client.commands.get(command).execute(message, client, args)
}
})
client.login(/*token*/)
./commands/ping.js
module.exports = {
name: "ping",
description: "Make me say pong",
async execute(client, message, args) {
message.channel.send("Pong!")
}
}
【问题讨论】:
标签: javascript discord.js