简体   繁体   English

无法读取未定义的属性“startsWith”

[英]Cannot read property 'startsWith' of undefined

I am using discord.js to make a discord bot.我正在使用 discord.js 制作一个 discord 机器人。 I keep getting the console error "Cannot read property 'startsWith' of undefined" how would I fix this??我不断收到控制台错误“无法读取未定义的属性‘startsWith’”,我该如何解决这个问题?

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.我猜你在消息事件 function 中。

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

I am using discord.js to make a discord bot.我正在使用 discord.js 制作 discord 机器人。 I keep getting the console error "Cannot read property 'startsWith' of undefined" how would I fix this??我不断收到控制台错误“无法读取未定义的属性'startsWith'”我将如何解决这个问题?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法读取 Discord.js 上未定义的属性“startsWith” - Cannot read property 'startsWith' of undefined on Discord.js 为什么我在此 for 循环中无法读取未定义的属性“startsWith”? - Why am I getting Cannot read property 'startsWith' of undefined in this for loop? JavaScript TypeError:无法读取未定义的属性'startsWith'-Discord Bot - JavaScript TypeError: Cannot read property 'startsWith' of undefined - discord bot 类型错误:无法读取新 DataSnapshot 中未定义的属性“startsWith” - TypeError: Cannot read property 'startsWith' of undefined at new DataSnapshot React Native [TypeError:无法读取未定义的属性'startsWith']? - React Native [TypeError: Cannot read property 'startsWith' of undefined]? JavaScript(discord.js)TypeError:无法读取未定义的属性“startsWith” - JavaScript(discord.js) TypeError: Cannot read property 'startsWith' of undefined Discord.JS UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“startsWith” - Discord.JS UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined 无法读取未定义要求('路径')解析的属性'startsWith' - Cannot read property 'startsWith' of undefined require('path') resolve Gatsby 插件图像无法读取属性“startsWith” - Gatsby plugin image cannot read property 'startsWith' TypeError:无法读取未定义 node.js V12.18.2 的属性“startsWith” - TypeError: Cannot read property 'startsWith' of undefined node.js V12.18.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM