0

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)
Lioness100
  • 8,260
  • 6
  • 18
  • 49
  • Does this answer your question? [What is the difference between a User and a GuildMember in discord.js?](https://stackoverflow.com/questions/63979076/what-is-the-difference-between-a-user-and-a-guildmember-in-discord-js) – Lioness100 Sep 20 '20 at 17:52

1 Answers1

1

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')) ...
Elitezen
  • 6,551
  • 6
  • 15
  • 29