简体   繁体   English

如何使用 python 在我的 discord 服务器中为每个人创建一个变量?

[英]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.

相关问题 如何为每个人发出邀请? - How can I make an invitation for each person? 如何让我的 Discord 机器人提及频道中的特定人员? - How can i make my Discord bot mention a specific person in the channel? 我怎样才能让我的 discord 机器人在键入时提到特定的人? - How can I make it so my discord bot mentions a specific person when they type? 如何使用 python 制作 discord 机器人来启动我的世界服务器? - How can I make discord bot for strarting minecraft server with python? 当语音频道中的人说话时,我可以让 discord python 机器人识别吗? - Can I make a discord python bot recognize when a person in a voice channel talks? 如何让我的 Discord.py 机器人计算一个人的消息? - How do I make, so my Discord.py bot counts a person's messages? 如何做到这一点,以便我的 discord 机器人只接受启动命令的人的输入 - How do I make it so my discord bot only take inputs from the person that started the command 如何使不和谐的机器人根据人员在命令中输入的内容来创建角色 - How can I make a discord bot create a role based on what the person types in the command 我将如何做到这一点,以便个人是唯一可以使用 discord 机器人运行命令的人? - How would I make it so that an individual person is the only one who can run a command with a discord bot? 我怎样才能让我只能在我的 Discord 机器人上使用某些命令? (Python) - How can I make sue only I can use certain commands on my Discord bot? (Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM