Home > Net >  How can I make my bot commands only run on servers and not on private messages?
How can I make my bot commands only run on servers and not on private messages?

Time:02-01

What happens is that if I send a command like the avatar command or some moderation command to the bot via private message, it causes an error because it doesn't get the properties it requires.

I am using discord js v12

CodePudding user response:

Use discord.js's message.inGuild() method.

if (!message.inGuild()) return;

or for an error message:

if (!message.inGuild()) return message.channel.send("Use this command in a guild!");
  •  Tags:  
  • Related