[英]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.我试图做到这一点,以便当用户键入命令时,它会检查他是否具有权限,但在所有方面(
hasPermissions
、 hasPermission
、 permissionsIn
)都会弹出相同的错误。
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.但是在您的情况下,它看起来
member
在message
中不存在(它返回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.