Reputation: 35
I made a command called throw party, which basically messages everyone in the server, but the admins of the server say its annoying that anyone can just spam serverparty, as its basically as annoying as spamming @everyone so I tried to make it a permission-based thing, but it wouldn't work here is the link to the discord guide I used: https://discordjs.guide/popular-topics/permissions.html#creating-a-role-with-permissions and here is the code:
if (cmd === 'throwparty') {
if (message.guild) {
if (message.author.hasPermission('MANAGE_SERVER')) {
message.guild.members.cache.forEach((member) => {
if (member.id != client.user.id && !member.user.bot)
member.send(args.join(' '));
});
} else {
message.channel.send('You dont have permission to use this');
}
// cuts off the /private part
}
}
Here's the error I got:
TypeError: message.author.hasPermission is not a function
at Client.<anonymous> (/home/runner/ServerParty/index.js:105:26)
at Client.emit (events.js:315:20)
at Client.EventEmitter.emit (domain.js:483:12)
at MessageCreateAction.handle (/home/runner/ServerParty/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/runner/ServerParty/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/runner/ServerParty/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/runner/ServerParty/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/runner/ServerParty/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/runner/ServerParty/node_modules/ws/lib/event-target.js:125:16)
Upvotes: 0
Views: 1465
Reputation: 6710
message.author
returns the user
property which doesn't have roles. You would need to get the member
instead.
message.member.hasPermission(...)
if (message.member.hasPermission('MANAGE_SERVER')) ...
Upvotes: 1