[英]error message in discord bot? (discord.js)
我正在制作一个事件和命令处理程序 evrything 看起来不错但是当我运行我的,hello
命令时我得到一个错误这里是错误:
if(.message.content.startsWith(Prefix) || message.author;bot) 返回; ^
TypeError:无法读取未定义的属性“startsWith”
这是代码:
module.exports = (Discord, Client, message) => {
const Prefix = ',';
if(!message.content.startsWith(Prefix) || message.author.bot) return;
const args = message.content.slice(Prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const Command = Client.commands.get(cmd);
if(Command) Command.execute(Client, message, args, Discord, Random, RadnomPuppy);
}
我没有看到任何问题
你的 function 有很多参数,所以消息是未定义的。 应该是这样的:
client.on("message", (msg)=>{
const Prefix = ',';
if(!msg.content.startsWith(Prefix) || msg.author.bot) return;
const args = msg.content.slice(Prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const Command = Client.commands.get(cmd); // Have the commands part in file scope, to access it here.
if(Command) Command.execute(Client, msg, args, Discord, Random, RadnomPuppy);
})
module.exports = (Discord, Client, message) => {
const Prefix = ',';
if(!message.content.startsWith(Prefix) || message.author.bot) return;
const args = message.content.slice(Prefix.length).split(/ +/);
const cmd = args.shift().toLowerCase();
const Command = Client.commands.get(cmd);
if(Command) Command.execute(Client, message, args, Discord);
}
我不得不从if(Command) Command.execute(Client, message, args, Discord);
中删除随机和随机小狗。 线
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.