0
votes

I am new to coding and especially to discord bots. I need help about a discord bot code that can help me store information. Lets say I want to make a list with some info: i.e: I want the command to be like !addtolist and then give email password and name

!addtolist [email protected] 1234 Lorem

after this, the bot stores the information. When I ask for the list (!list command) I want the bot to show me the list of all emails passwords and names that I have entered. i.e

  • List item

!list

  1. [email protected] 1234 Lorem
  2. [email protected] 1234 Lorem
  3. etc

Thank you

1
Just as a note, you should NEVER store a password in plain text. - Snel23
It is only for personal use. And if you are referring to the question above, its just an example. Thanks @Snel23 - Sergio
As for going about this problem, you can either store all of the information into a variable, but will all be lost if the bot gets turned off. You could instead save the information to a file in your local drive using the fs package, but this won't work if you are hosting your bot on something like heroku, because heroku does not have persistent file storage. If this is they way you were going about it, you could instead save the data into ta database. If you can decide what kind of way you want this to work, i am happy to help you out with one of these options - Snel23

1 Answers

0
votes

you can do it like this:

bot = commands.Bot(command_prefix='!')
bot_list = []

@bot.command(help='Adds an item to a list')
async def addtolist(ctx, item):
    global bot_list
    bot_list.append(item)
    ctx.send(f'item added to list successfully\nList is now: {bot_list}')

@bot.command(help='Shows bot list')
async def showlist(ctx)
    ctx.send(bot_list)