简体   繁体   中英

Cannot read property 'startsWith' of undefined

I am using discord.js to make a discord bot. I keep getting the console error "Cannot read property 'startsWith' of undefined" how would I fix this??

Here is the code snippet

if(Discord.Message.content.startsWith('>ban')){
        if(Discord.Message.member.guild.me.hasPermission('BAN_MEMBERS'))
        {
            if(Discord.Message.mentions.members.first()) 
            {
                Discord.Message.mentions.members.first.ban().then((member) => {
                    Discord.Message.channel.send("**BANNED** " + member.displayName + " has been banned:hammer:");
                }).catch(()=> {
                    Discord.Message.channel.send("You do not have permission to ban that user... If you think this is an issue, please contact a server administrator");
                })
            }
        }
    }

I guess you're in the on message event function.

client.on('message', message => {
  if (message.content.startsWith('>ban')) {
    // do your stuff
  }
})

I am using discord.js to make a discord bot. I keep getting the console error "Cannot read property 'startsWith' of undefined" how would I fix this??

Here is the code snippet

if(Discord.Message.content.startsWith('>ban')){
        if(Discord.Message.member.guild.me.hasPermission('BAN_MEMBERS'))
        {
            if(Discord.Message.mentions.members.first()) 
            {
                Discord.Message.mentions.members.first.ban().then((member) => {
                    Discord.Message.channel.send("**BANNED** " + member.displayName + " has been banned:hammer:");
                }).catch(()=> {
                    Discord.Message.channel.send("You do not have permission to ban that user... If you think this is an issue, please contact a server administrator");
                })
            }
        }
    }

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