【发布时间】:2020-12-18 01:42:49
【问题描述】:
我试过这些代码
def get_prefix(client, message):
with open('prefixes.json', 'r') as f:
prefixes = json.load(float)
return prefixes[str(message.guild.id)]
client = commands.Bot(command_prefix = get_prefix)
@client.event
async def on_guild_join(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(float)
prefixes[str(guild.id)] = ','
with open('prefixes.json', 'w') as f:
json.dump(prefixes, float, indent=4)
@client.event
async def on_guild_remove(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes.pop(str(guild.id))
with open('prefixes.json', 'w') as float:
json.dump(prefixes, float, indent=4)
@client.command()
@commands.has_permissions(manage_channels=True)
async def prefix(ctx, prefix):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(ctx.guild.id)] = prefix
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
await ctx.send(f'Prefix changed succesfully, now my prefix for this server is: "{prefix}"')
我得到了这些错误
忽略 on_message 中的异常 回溯(最近一次通话最后): _run_event 中的文件“C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py”,> 第 312 行 等待 coro(*args, **kwargs) 文件“C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py”,第 943 行,on_message 等待 self.process_commands(消息) 文件“C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py”,第 939 行,在 process_commands ctx = 等待 self.get_context(消息) 文件“C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py”,第 853 行,在 get_context 前缀 = 等待 self.get_prefix(消息) 文件“C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py”,第 798 行,在 get_prefix ret = await discord.utils.maybe_coroutine(前缀,自我,消息) 文件“C:\Users\PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\utils.py”,行 >331,在 maybe_coroutine 中 值 = f(*args, **kwargs) 文件“C:\Users\PC\Desktop\Code\Project 01\index.py”,第 20 行,在 get_prefix 返回前缀[str(message.guild.id)] 键错误:'744103149471662152'
请帮忙,几周前它还在工作。
【问题讨论】:
-
您能解释一下
json.load(float)和json.dump(.., float,..)的作用吗?你的意思是f? -
我试着把它改成 F 到 Float 还是一样的错误
标签: python python-3.x discord.py discord.py-rewrite