简体   繁体   English

我不断收到有关 discord.js 中 .position 的错误

[英]i keep getting an error about .position in discord.js

So i tried making a kick command in dicors.js(creating a bot).所以我尝试在 dicors.js 中创建一个 kick 命令(创建一个机器人)。 I did a little bit of research and I ended up with copying a code from stack overflow.我做了一些研究,最终从堆栈溢出中复制了一段代码。 The code was working fine but i wanned to make it so if "x" that has a lower rank tries to kick "y" which has higher rank, the bot would then send a message to "x" that he can't kick a higher rank person.代码运行良好,但我想这样做,如果具有较低等级的“x”试图踢具有较高等级的“y”,则机器人会向“x”发送一条消息,表明他不能踢级别较高的人。 (both x and y are users) (x 和 y 都是用户)

The code that i copied also has this function included and i keep getting this error我复制的代码也包含此功能,但我不断收到此错误

let authorHighestRole = msg.member.highestRole.position;
                                               ^
TypeError: Cannot read property 'position' of undefined

I searched online: nothing.我在网上搜索:没有。 I tried some stupid things like adding () to .position I searched in the Discord.js docs and still nothing.我尝试了一些愚蠢的事情,例如将 () 添加到 .position 我在 Discord.js 文档中搜索过,但仍然没有。

I came to the conclusion that the code is old.我得出的结论是代码很旧。

Here is my code这是我的代码

case 'kick' :
            if(msg.channel.type === 'DM') {
                msg.channel.send('This command can use only in guide');
                return;
            };
    
            if(!msg.member.hasPermission('KICK_MEMBERS')) {
                msg.channel.send('You have no permissions to do that');
                return;
            };
    
            let mentionMember = msg.mentions.members.first();
            if(!mentionMember) {
                msg.channel.send('Please specify the person you want to kick!');
                return;
            }
    
            if(!mentionMember.kickable) {
                msg.channel.send('I can\'t kick this user!');
                return
            };

            //Get the highest role of user for compare
            let authorHighestRole = msg.member.highestRole.position;
            let mentionHighestRole = mentionMember.highestRole.position;

            //If mention user have same or higher role, so show this error msg
            if(mentionHighestRole >= authorHighestRole) {
                msg.channel.send('You can`t kick members with equal or higher position');
                return;
            };
        
            mentionMember.kick()
                msg.channel.send(`${mentionMember.displayName} was kicked`)
        break;

Any help would be appreciated.任何帮助,将不胜感激。

member doesn't contain a property called highestRole, I believe the property you're looking for is: member.roles.heighest.成员不包含名为highestRole 的属性,我相信您要查找的属性是:member.roles.heighest。

see docs: https://discord.js.org/#/docs/main/stable/class/GuildMemberRoleManager?scrollTo=highest见文档: https : //discord.js.org/#/docs/main/stable/class/GuildMemberRoleManager? scrollTo =highest

msg.member.roles.highest.position

暂无
暂无

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

相关问题 我的解禁命令 discord.js v13 一直出现此错误 - I keep getting this error on my unban command discord.js v13 在 discord.js 上编写一个不和谐的机器人,我不断收到错误“TypeError [ClientMissingIntents]:必须为客户端提供有效的意图。” - Coding a discord bot on discord.js and i keep getting the error "TypeError [ClientMissingIntents]: Valid intents must be provided for the Client." 我在 discord.js 中制作头像机器人时出错 - I'm getting an error in making avatar bot in discord.js 为什么我在 discord.js 中收到客户端错误 - Why am I getting a client error in discord.js "<i>&quot;The reply to this interaction has not been sent or deferred.&quot;<\/i> “对此互动的回复尚未发送或推迟。”<\/b> <i>Is an error I keep getting on discord.js v13<\/i>是我在 discord.js v13 上不断出现的错误吗<\/b>" - "The reply to this interaction has not been sent or deferred." Is an error I keep getting on discord.js v13 在 discord.js bot 中的 client.commands.get 上执行未定义读取时不断出现错误 - Keep getting error for undefined reading execute on client.commands.get in discord.js bot discord.js 我不断收到机器人所说的而不是用户的消息 - discord.js I keep getting what the bot says instead of user's message Discord.js 关于让用户对嵌入做出反应的问题{更新} - Discord.js Question about getting the user that reacted to the embed {Updated} 我该如何处理错误、忽略它并继续使用该函数? 不和谐.js - How can I go about handling an error, ignoring it and continuing with the function? discord.js 使用 NPM、node.js 和 discord.js,我不断收到 TypeError: Cannot read property 'setPresence' of Z37A6259CC0C1DAE0294 - Using NPM, node.js and discord.js, I keep getting TypeError: Cannot read property 'setPresence' of null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM