简体   繁体   English

无法从 null discord.js v11 读取属性

[英]Cannot read properties from null discord.js v11

rs\asus\Desktop\dc bot 11.5.1\index.js:39
        if(!msg.member.permissionsIn(channel).has("MANAGE_MESSAGES"))
                       ^

TypeError: Cannot read properties of null (reading 'permissionsIn')
    at Client.<anonymous> (C:\Users\asus\Desktop\dc bot 11.5.1\index.js:39:24)
    at Client.emit (node:events:390:28)
    at MessageCreateHandler.handle (C:\Users\asus\Desktop\dc bot 11.5.1\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (C:\Users\asus\Desktop\dc bot 11.5.1\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (C:\Users\asus\Desktop\dc bot 11.5.1\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (C:\Users\asus\Desktop\dc bot 11.5.1\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Users\asus\Desktop\dc bot 11.5.1\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (node:events:390:28)
    at Receiver.receiverOnMessage (C:\Users\asus\Desktop\dc bot 11.5.1\node_modules\ws\lib\websocket.js:789:20)
    at Receiver.emit (node:events:390:28)

Node.js v17.1.0
[nodemon] app crashed - waiting for file changes before starting...

I know it is discord.js v11 but it is more functional in my opinion.我知道它是 discord.js v11,但我认为它更实用。 But before you convince me I will say one thing on discord.js v13 the same error occurred!但在你说服我之前,我会在 discord.js v13 上说一件事,同样的错误发生了! The exact same thing!完全一样的东西!

I tried to make it so that when a user types a command, it checks if he has permissions, but in all ways ( hasPermissions , hasPermission , permissionsIn ) the same error pops up.我试图做到这一点,以便当用户键入命令时,它会检查他是否具有权限,但在所有方面( hasPermissionshasPermissionpermissionsIn )都会弹出相同的错误。

This is my code:这是我的代码:

client.on("message", msg =>{
    const {channel,author,guild,member} = msg;
    
    const args = msg.content.slice(prefix.length).trim().split(/ +/g);
    const cmd = args.shift().toLowerCase();
    if(author.bot) return;
if(cmd=="clear")
    {
        if(!guild.me.permissionsIn(channel).has(["SEND_MESSAGES"]))
        {
            return;
        }
        if(!guild.me.permissionsIn(channel).has(["MANAGE_MESSAGES"])){
            msg.channel.send("Im not have the `MANAGE MESSAGES` permission, but is this required fot this action!");
            return;
        }
        if(!msg.member.hasPermissions(["MANAGE_MESSAGES"]))
        {
            const replyEmbed = new Discord.RichEmbed()
            .setTitle("Komenda odrzucona!")
            .setColor("#ff0000")
            .setDescription("Nie posiadasz uprawnienia `ZARZĄDZANIE WIADOMOŚCIAMI`")
            .setFooter("Requested by "+msg.author.tag);
            msg.channel.send(replyEmbed);
            return;
        }
        const amount = parseInt(args[0]);


         if(!Number.isInteger(amount))
        {
            const replyEmbed = new Discord.RichEmbed()
            .setTitle("Komenda odrzucona!")
            .setColor("#ff0000")
            .setDescription("Nie podałeś liczby! Musi być to konkretna liczba naturalna lub całkowita!")
            .setFooter("Requested by "+msg.author.tag);
            msg.channel.send(replyEmbed);
            return;
        }
        if(args.length<1)
        {
            const replyEmbed = new Discord.RichEmbed()
            .setTitle("Komenda odrzucona!")
            .setColor("#ff0000")
            .setDescription("Komenda przyjmuje co najmniej 1 argument i musi być to liczba!")
            .setFooter("Requested by "+msg.author.tag);
            msg.channel.send(replyEmbed);
            return;
        }
       if(amount>100)
       {
        const replyEmbed = new Discord.RichEmbed()
        .setTitle("Komenda odrzucona!")
        .setColor("#ff0000")
        .setDescription("Ta liczba nie może być większa niż 100!")
        .setFooter("Requested by "+msg.author.tag);
        msg.channel.send(replyEmbed);
        return;
       }
        if(amount == 0)
        {
            amount++;
            amount++;
        }
        msg.channel.bulkDelete(amount);
        const replySuccess = new Discord.RichEmbed()
        .setTitle("Sukces")
        .setColor("#1cfc03")
        .setDescription("✅ Poprawnie usunięto "+amount+" wiadomości!")
        .setFooter("Requested by "+msg.author.tag);
        msg.channel.send(replySuccess);
    
    }

Discord now uses message.member.permissions.has() : https://discord.js.org/#/docs/main/stable/class/Permissions Discord 现在使用message.member.permissions.has()https://discord.js.org/#/docs/main/stable/class/Permissions

But in your case, it looks member doesn't exist on message (it returns null ).Try a console.log() on message.member to see if it exists.但是在您的情况下,它看起来membermessage中不存在(它返回null )。尝试在message.member上执行console.log()以查看它是否存在。 Otherwise, refer to the documentation and use message.member.permissions.has() instead of message.member.permissionsIn(channel).has(permission) .否则,请参阅文档并使用message.member.permissions.has()而不是message.member.permissionsIn(channel).has(permission)

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

相关问题 如何将我的代码从 v11 迁移到 Discord.js v12? - How can I migrate my code to Discord.js v12 from v11? Node.js Discord.js 从 ID v11 向通道发送消息 - Node.js Discord.js Send message to channel from ID v11 有什么方法可以从用户 object 那里获取 dmChannel id? (discord.js v11) - Is there any way to get a dmChannel id just from the user object? (discord.js v11) Discord.js:类型错误:无法读取 null 的属性(读取“状态”) - Discord.js: TypeError: Cannot read properties of null (reading 'status') Discord JS V11禁令命令 - Discord JS V11 BAN COMMAND 从 v11 迁移后,无法在 discord.js v12 中从服务器设置用户状态和记录用户数量 - Cant set user status and log user amount from server in discord.js v12 after migrating from v11 TypeError:无法在 discord.js v13 中读取未定义的属性(读取“路径”) - TypeError: Cannot read properties of undefined (reading 'path') in discord.js v13 discord.js v13 - 类型错误:无法读取未定义的属性(读取“正常运行时间”) - discord.js v13 - TypeError: Cannot read properties of undefined (reading 'uptime') 类型错误:无法读取未定义的属性(读取“回复”)- discord.js v14 - TypeError: Cannot read properties of undefined (reading 'reply') - discord.js v14 无法读取未定义的属性(读取“权限”)。 | Discord.js v13 - Cannot read properties of undefined (reading 'permissions'). | Discord.js v13
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM