Skip to content

Commit

Permalink
🐛 Check channel before responding to custom commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Androz2091 committed Dec 3, 2020
1 parent d064c34 commit 4d49c1d
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions events/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,26 @@ module.exports = class {
const args = message.content.slice((typeof prefix === "string" ? prefix.length : 0)).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const cmd = client.commands.get(command) || client.commands.get(client.aliases.get(command));

if(!cmd){
if(message.guild){
const customCommand = data.guild.customCommands.find((c) => c.name === command);
if(customCommand){
message.channel.send(customCommand.answer);
}
return;
} else {
return message.sendT("misc:HELLO_DM", {
username: message.author.username
});
}

const customCommand = message.guild ? data.guild.customCommands.find((c) => c.name === command) : null;
const customCommandAnswer = customCommand ? customCommandAnswer.answer : '';

if(!cmd && !customCommandAnswer){
return message.sendT("misc:HELLO_DM", {
username: message.author.username
});
}

if(data.guild.ignoredChannels.includes(message.channel.id) && !message.member.hasPermission("MANAGE_MESSAGES")){
message.delete();
message.author.send(message.translate("misc:RESTRICTED_CHANNEL", {
channel: message.channel.toString()
}));
return;
}

if (customCommandAnswer) {
return message.channel.send(customCommandAnswer);
}

if(cmd.conf.guildOnly && !message.guild){
Expand Down Expand Up @@ -173,14 +180,6 @@ module.exports = class {
list: neededPermissions.map((p) => `\`${p}\``).join(", ")
});
}
if(data.guild.ignoredChannels.includes(message.channel.id) && !message.member.hasPermission("MANAGE_MESSAGES")){
message.delete();
message.author.send(message.translate("misc:RESTRICTED_CHANNEL", {
channel: message.channel.toString()
}));
return;
}

if(!message.channel.permissionsFor(message.member).has("MENTION_EVERYONE") && (message.content.includes("@everyone") || message.content.includes("@here"))){
return message.error("misc:EVERYONE_MENTION");
}
Expand Down

0 comments on commit 4d49c1d

Please sign in to comment.