Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need help reassigning a variable in a bot menu

I am trying to build a setup menu for my bot that the server owner can use to configure the bot. The menu is triggered when the owner types =setup. I want the bot to reply with several embed messages asking the user questions in order to correctly configure the bot.

This is my first Discord.js project so I am unaware of the syntax but trying to learn. I have a constant variable called prefix assigned to = when the bot is implemented into the server.

The first prompt on the bot menu asks the user to change the prefix to anything they want. I need help understanding how to reassign my original constant variable to the new prefix they are requesting.

var PREFIX = '=';

bot.on('message', message=>{
    let args = message.content.substring(PREFIX.length).split(" ");

    switch(args[0]){
        case 'setup':
            const embed = new Discord.RichEmbed()
            .setTitle('Step 1 of 1')
            .setDescription('Set your Prefix')
            .setColor(0xF1C40F)
            message.channel.sendEmbed(embed);
            //I want the user to now enter their own PREFIX and have the
            //bot save their responce as the new PREFIX
        break;
    }
})

What I want to happen is when the user types their desired prefix, the bot will reassign prefix in the code, and delete the bots question and the users response and begin to prompt them with the next question.

like image 290
StealthProxy Avatar asked Oct 17 '19 20:10

StealthProxy


1 Answers

depending if your bot is going to be in multiple servers with different prefixes:

  • If so then you need a database to save the prefix for each server and then get it when a user sends a message from that server
  • If not I would use a json file to store the prefix, then have node edit the file when it needs to change

Or look at https://discordjs.guide/keyv/ there is a great tutorial there to do what you want

like image 112
mmoomocow Avatar answered Oct 12 '22 13:10

mmoomocow