R
R
Roman Shavukhin2020-10-02 17:36:31
Python
Roman Shavukhin, 2020-10-02 17:36:31

How to add a user to the User#1234 list?

I'm making a Discord bot that adds user data to a list like User#1234 if the user is not in the list. But I can’t add this data to the list or they are not saved
here is the code

@bot.command()
async def start(ctx):
  if ctx.author == bot.user:
    return
  if ctx.author not in u_l:
    if ctx.channel.recipient.bot == True:
      return
    else:
      u_l.append(ctx.author)
      print(ctx.author) 
      print(u_l)
      return
  else:
    return

On output goes:
User#1234
This is output on
print(ctx.author)
[<User id=1234567890123456789 name='User' discriminator='1234' bot=False>]
And this is the same value, but stored in a list
So the question is, why is this happening and how to fix it?
upd:
I fixed the input to the list like this:
user_base_info = (ctx.author.name + '#' +ctx.author.discriminator)
u_l.append(user_base_info)

But after restarting the program, the dictionary is reset
. Does anyone know how to save the data?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2020-10-02
@x3ron

If you want to store users, it's best to store them by their ID, the name and discriminator can easily be changed, and are not reliable storage methods.
All variables in python (as in most other languages) are stored in RAM, and are "forgotten" as soon as the process ends. If you want to store data between "sessions", you need to save it to disk and load it from there. The simplest version of this, in my opinion, is json .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question