discordjs / guide

The official guide for discord.js, created and maintained by core members of its community.
https://discordjs.guide
MIT License
1.57k stars 2.31k forks source link

"I can't execute that command inside DMs" could possibly misfire #453

Closed JavascriptLearner815 closed 4 years ago

JavascriptLearner815 commented 4 years ago

Part of the guide or code sample the question is about https://discordjs.guide/command-handling/adding-features.html#guild-only-commands

Question The check for DMs checks for two things, one, if the command is for guilds only. Two, it checks if the channel is not a text channel. There is a slight issue with this. If you turn on Community, and make an announcements channel, and try to use a bot command that is for guilds only, it would say, "I can't execute that command inside DMs!".

So, why doesn't the if statement look like this?

if (command.guildOnly && message.channel.type === 'dm') { return message.reply('I can\'t execute that command inside DMs!'); }

almostSouji commented 4 years ago

Good catch! This part of the guide was written when "text" type channels were the only text-based channel on guilds and another type of dm channel existed.

Discord tried to or at least thought about partially supporting group dm channels for bots, however has stopped that functionality completely. So now the requirements have turned around from "we need to only let this one channel type through" to "we only need to prevent it from executing in this channel type".