首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Discord.py重写多服务器数据

Discord.py重写多服务器数据
EN

Stack Overflow用户
提问于 2018-10-05 22:24:05
回答 1查看 839关注 0票数 1

所以我使用discord.py已经有一段时间了,最近切换到了discord.py-rewrite。我似乎找不到任何关于如何做到这一点的东西。但我想要每个行会的数据。例如,如果机器人在Server 1中,而Owner1-prefix !!中,它会将其添加到它们的前缀中,但仅在它们的行会中。因此它不会是Server2中的前缀。任何帮助都是最好的。有人告诉我,我可以用JSON文件做到这一点,但我在上面找不到任何我想要的东西。

EN

回答 1

Stack Overflow用户

发布于 2019-07-05 21:32:04

我自己就是一个不和谐的机器人制造者,有时我会遇到这个问题。我已经为此创建了一个变通方法。

你需要的是一个字典而不是变量。字典的关键字是行会属性,值是该行会的日期。

下面是我的代码片段:

代码语言:javascript
复制
# Changing variables and setting them
#--------------------------------------------------------------

# Changing the values of a dictionary.
def guildvarchg(variable, guild, value): # Guild Variable Change
    for key in variable.keys(): # Do not change any of this.
        if key == guild:
            variable[key] = value

# To get a certain guild's variable, add [guild id] to the dictionary name.
# For example: variable[ctx.author.guild] # takes the data for that guild

# You are going to run into a first time setup issue. 
# To counter this, and for every new guild, add this if statement:

if ctx.author.guild not in variable: # only use this in a command definition
    variable[ctx.author.guild] = 'New value' # adds a new server to the data.
else:
    guildvarchg(variable, ctx.author.guild, new_value) # <<< overwrites the server data


#--------------------------------------------------------------

建议您在运行之前创建所有变量字典

代码语言:javascript
复制
variable{None:None} # Format after setting: variable{guild_id, data}

如果你觉得这很有用,请接受这个答案,并与你的朋友分享这段代码。我想很多人都需要它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52667764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档