繁体   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...

我知道它是 discord.js v11,但我认为它更实用。 但在你说服我之前,我会在 discord.js v13 上说一件事,同样的错误发生了! 完全一样的东西!

我试图做到这一点,以便当用户键入命令时,它会检查他是否具有权限,但在所有方面( hasPermissionshasPermissionpermissionsIn )都会弹出相同的错误。

这是我的代码:

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 现在使用message.member.permissions.has()https://discord.js.org/#/docs/main/stable/class/Permissions

但是在您的情况下,它看起来membermessage中不存在(它返回null )。尝试在message.member上执行console.log()以查看它是否存在。 否则,请参阅文档并使用message.member.permissions.has()而不是message.member.permissionsIn(channel).has(permission)

暂无
暂无

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

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