S
S
ssurskikh2021-04-03 13:20:11
Node.js
ssurskikh, 2021-04-03 13:20:11

How to fix prefix in bot (Discord.js)?

I'm developing a bot in discord, but at one point the bot started responding to all prefixes (which shouldn't be)!
how do i fix this? there are no errors in the console!

the code in which everything is processed:

const Event = require('../../Structures/Event');

module.exports = class extends Event {

  async run(message) {
    const mentionRegex = RegExp(`^<@!${this.client.user.id}>$`);
    const mentionRegexPrefix = RegExp(`^<@!${this.client.user.id}> `);

    if (!message.guild || message.author.bot) return;

    if (message.content.match(mentionRegex)) message.channel.send(`My prefix for ${message.guild.name} is \`${this.client.prefix}\`.`);

    const prefix = message.content.match(mentionRegexPrefix) ?
      message.content.match(mentionRegexPrefix)[0] : this.client.prefix;

    const [cmd, ...args] = message.content.slice(prefix.length).trim().split(/ +/g);

    const command = this.client.commands.get(cmd.toLowerCase()) || this.client.commands.get(this.client.aliases.get(cmd.toLowerCase()));
    if (command) {
      command.run(message, args);
    }
    if(message.author.id === this.client.user.id || !message.content.startsWith(prefix)) return;
  }

};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
ssurskikh, 2021-04-11
@ssurskikh

I already solved it!
it was in

if(message.author.id === this.client.user.id || !message.content.startsWith(prefix)) return;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question