Search code examples
javascriptdiscorddiscord.jsbots

Discord.js Bot settings when changed on one server changes on all of them running it on repl.it


Hi so there really isn't much to the problem above I just need to know how to separate the settings on one server from the settings on another server. Here is the code I am currently using!

client.on('message', (msg) => {
if (msg.content == `${prefix}setup`) {
    msg.channel.send('To set the prefix use !prefix set (the prefix)');
    msg.channel.send('To set the code prefix use !prefix code (the prefix preferably your yt name)');
    msg.channel.send('Make sure to set the channel for early code release/access use !early set (id of the channel)');
  } else if (msg.content.startsWith(`${prefix}prefix set`)) {
    prefix = msg.content.replace(`${prefix}prefix set`, '').trim()
    console.log(prefix)
    msg.channel.send('Prefix Changed!')
  } else if (msg.content.startsWith(`${prefix}prefix code`)) {
    name = msg.content.replace(`${prefix}prefix code`, '').trim()
    console.log(name)
    client.channels.cache.get(early).send(`Prefix set to ${name}`)
    code = `New code is ${name}${Math.floor(Math.random() * 101)}`
    client.channels.cache.get(early).send(`${code}`);
  } else if (msg.content.startsWith(`${prefix}early set`)) {
    early = msg.content.replace(`${prefix}early set`, '').trim()
    console.log(early)
    msg.channel.send('Early Channel Changed!')
  } else if (msg.content == `${prefix}new code`) {
    code = `code is ${name}${Math.floor(Math.random() * 101)}`
    msg.channel.send(`New ${code}`)
  }
});

Solution

  • You would need a database for individual server settings. Thankfully, this is very easy to do. You can use discord-prefix.


    Discord Prefix

    Discord Prefix is a simple Node.js module that lets you efficiently manage custom prefixes for your discord bot

    Install

    npm i discord-prefix
    

    Github

    RedLukeBug/discord-prefix


    Hoped this helped!