I'm trying to code a Discord game bot on repl.it and I use its database to store the players' data.
So I'm now making a command to let players rename themselves but then there is a problem. The following lines work but involve affecting a new value to the entire player_data
list which stores the data of every player:
renamer = player_id.index(message.author.id)
new_name = message.content[len(prefix)+7:]
player_data = db["player_data"]
player_data[renamer][0] = new_name
db["player_data"] = player_data
await message.channel.send('You successfully renamed yourself into '+new_name+'.')
So I'm afraid that if someone starts playing while another is changing his nickname, the 'old' player_data
will overwrite the new one, which has the new player's data.
I want something similar to these lines (which don't work) to only change the involved player's data:
renamer = player_id.index(message.author.id)
new_name = message.content[len(prefix)+7:]
db["player_data"][renamer][0] = new_name
await message.channel.send('You successfully renamed yourself into '+new_name+'.')
question from:
https://stackoverflow.com/questions/65517015/how-to-change-only-one-value-of-a-list-from-repl-it-database 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…