[英]How can I make a variable for each person in my discord server with python?
I am making a game for my discord server, and I need every member of the discord server to have their own number of coins.我正在为我的 discord 服务器制作游戏,我需要 discord 服务器的每个成员都有自己的硬币数量。 Therefore, I need every member of my discord server to have their own variable for their coins.因此,我需要我的 discord 服务器的每个成员都有自己的硬币变量。 If anyone knows how I could do this that would be a huge help.如果有人知道我怎么能做到这一点,那将是一个巨大的帮助。 Thanks.谢谢。
You can do that using a dictionary where the keys might be the usernames of each player and values are the number of coins that user has.您可以使用字典来做到这一点,其中键可能是每个玩家的用户名,值是用户拥有的硬币数量。
Say you have a list of usernames called usernames and each player initially has 10 coins, The code would be something similar to this:假设您有一个名为 usernames 的用户名列表,每个玩家最初有 10 个硬币,代码将类似于以下内容:
usernames = ['jason', 'jack', 'hunter']
coins = 10
players = {}
for user in usernames:
players[user] = 10
print(players)
Output would be this: Output 将是这样的:
{'jason': 10, 'jack': 10, 'hunter': 10}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.