M
M
MoneySMile2021-07-30 12:55:12
Node.js
MoneySMile, 2021-07-30 12:55:12

The bot responds to all prefixes. How to make discord.js only respond to one specific prefix?

My bot reacts to all prefixes like "+" "!" "=" "/" etc.
How can I fix this?
I need the bot to react to only one prefix "!"
Maybe a bug in the code?

The code
const Discord = require('discord.js');
const bot = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
const fs = require('fs');
let commands= [];
const cfg = require('./cfg.json');
const { MessageEmbed } = require('discord.js');

module.exports.bot = bot

fs.readdir("./commands",(err, files) => {
    if(err) throw err;
  files.map(f => require(`./commands/${f}`));
  commands = files.filter(f => f.endsWith(".js") && !f.startsWith("i_")).map(f => require(`./commands/${f}`))
  });

  bot.on("message",async message =>  {
  if(message.author.bot) return;
  if(message.mentions.users.first() == bot.user) {
    
}
  let args = message.content.split(" ");
  let member = message.mentions.members.first() || message.member;
  let cmd = commands.find(c => c.properities.name.includes(args[0].slice(cfg.prefix.length)));
  if(cmd) cmd.run(bot,message,member,args.slice(1),commands);
  });

  bot.login(cfg.token);

cfg
{
    "token":"тут_мой_токен",
    "prefix":"!"
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vItalIyIrtlach, 2021-07-30
@MoneySMile

You don't have check for message start message.content.startsWith("prefix")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question