# 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
#--------------------------------------------------------------
建议您在运行前创建所有变量[字典]
variable{None:None} # Format after setting: variable{guild_id, data}
1条答案
按热度按时间dgjrabp21#
我是一个不和谐的机器人制造商自己,有时我有这个问题。我为此创建了一个解决方案。
你需要的是字典而不是变量。字典的键是公会属性,值是该公会的日期。
下面是我的代码片段:
建议您在运行前创建所有变量[字典]