Skip to content

Commit

Permalink
fix(discord): fix bot not responding to mention prefixes in guilds
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Feb 6, 2022
1 parent 95d65fc commit 178e6ed
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/Discord/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,24 @@ class Client extends DiscordClient {
*/
async execute(msg) {
if (msg.author.equals(this.user) || msg.author.bot) return;
const prefix = msg.guild && Guild.getPrefix(msg.guild) || this.prefix;
const prefix = (msg.guild && Guild.getPrefix(msg.guild)) || this.prefix;

const userMention = this.user.toString();
const botMention = userMention.replace('@', '@!');

if (
msg.channel.type !== 'dm' &&
!msg.content.startsWith(this.user.toString()) &&
!msg.content.startsWith(userMention) &&
!msg.content.startsWith(botMention) &&
!msg.content.startsWith(prefix) &&
!msg.content.startsWith(this.prefix)
)
return false;

const content =
(msg.content.startsWith(prefix) && msg.content.replace(prefix, '')) ||
(msg.content.startsWith(this.user.toString()) && msg.content.replace(`${this.user.toString()} `, '')) ||
(msg.content.startsWith(userMention) && msg.content.replace(`${userMention} `, '')) ||
(msg.content.startsWith(botMention) && msg.content.replace(`${botMention} `, '')) ||
(msg.content.startsWith(this.prefix) && msg.content.replace(this.prefix, '')) ||
msg.content;
const command = content.split(' ')[0].toLowerCase();
Expand Down

0 comments on commit 178e6ed

Please sign in to comment.