我有一个发送文本的命令
示例copypata.json:
{
"xxx" : "xxxxxx xxxx xxxxx xxxxx...",
"yyy" : "yyyyyy yyyy yyyyy yyyyy...",
"zzz" : "zzzzzz zzzz zzzzz zzzzz..."
}
发送文本的代码:
json_file = 'copypasta.json'
with open(json_file) as json_data:
jsonLoad = json.load(json_data)
aliases = list(jsonLoad.keys())
@client.command(aliases=aliases) #problem is here
async def _copypasta(ctx):
keyCopypasta = ctx.invoked_with
valueCopypasta = jsonLoad[keyCopypasta]
await ctx.send(valueCopypasta)
如果我在Discord中发送-xxx,则bot会发送json“xxxx xxx…”中的值
因此,我发出了一个命令,在json中添加一个新元素:
async def addCopypasta(ctx, key, *, value):
a_dictionary = {key: value}
with open("copypasta.json", "r+") as file:
data = json.load(file)
data.update(a_dictionary)
file.seek(0)
json.dump(data, file)
await ctx.send("successfully added")
但是当我在Discord中发送添加的新元素的键时,bot没有找到它,我需要重新启动bot,以便更新命令的“alias”变量
是否可以在不重新启动bot的情况下更新命令别名
可以只需删除命令、更新别名并再次添加命令,一个方便的功能是:
要使用它:
相关问题 更多 >
编程相关推荐