{ if(message.author.bot || message.channel.type === 'dm') return; let prefix = b" /> { if(message.author.bot || message.channel.type === 'dm') return; let prefix = b" /> { if(message.author.bot || message.channel.type === 'dm') return; let prefix = b"/>

The Discord.js command I wrote does not working

48 views Asked by At

I have an error in these codes.

client.on("message", async message => {
  if(message.author.bot || message.channel.type === 'dm') return;

  let prefix = botsettings.prefix;
  let messageArray = message.content.split(" ");
  let cmd = messageArray[0];
  let args = message.content.substring(message.content.indexOf(' ')+1);

  if(!message.content.startsWith(prefix)) return;
  let commandfile = bot.commands.get(cmd.slice(prefix.lenght)) || bot.commands.get(bot.aliases.get(cmd.slice(prefix.lenght)))
  if(commandfile) commandfile.run(bot,message,args)

  if(cmd === `${prefix} reactions`){
    let embed = new Discord.MessageEmbed()
    .setTitle('Reaction Roles')
    .setDescription('Kişiliğinize göre bir rol seçiniz.')
    .setColor('GREEN')
    let msgEmbed = await message.channel.send(embed).
    msgEmbed.react(':closed_book:')
  }
})

I am encountering this error. I couldn't find the botsettings part.

UnhandledPromiseRejectionWarning: ReferenceError: botsettings is not defined

2

There are 2 answers

3
Aci On

This means that you didn't define the "botsettings" file anywhere. Try adding

const botsettings = require ("<path to the file>")

to the top of your code.

1
Flying Kart On

If you're trying to make commands, try using this. I use it a lot in my bot (currently v11, too much of a hassle to update to v12. But the same code should work anyway.):

client.on("message", async (message) => {
  if(message.author.bot) return;
  const args = message.content.slice(botsettings.prefix.length).trim().split(' ');
  const command = args.shift().toLowerCase();
  if (message.content.indexOf(botsettings.prefix) !== 0) return;

 if(command === "reactions"){
    let embed = new Discord.MessageEmbed()
    .setTitle('Reaction Roles')
    .setDescription('Kişiliğinize göre bir rol seçiniz.')
    .setColor('GREEN')
    let msgEmbed = await message.channel.send(embed).
    msgEmbed.react(':closed_book:')
  }
});

Before doing this, make sure you have r const botsettings = ("./path/to/your/botsettings.json"); at the top of your entire code.