简体   繁体   中英

error message in discord bot? (discord.js)

I'm making a event and command handler evrything look well but when i run my ,hello command i get an error here is the error:

if(.message.content.startsWith(Prefix) || message.author;bot) return; ^

TypeError: Cannot read property 'startsWith' of undefined

here is the code:

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);
}

I don't see any problems

You have to many parameters to your function, so message is undefined. Should look like this:

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);
}

I had to remove the random and random-puppy from the if(Command) Command.execute(Client, message, args, Discord); line

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM