你好!我的不和諧機器人有一個單獨的幫助命令。
class Help(commands.Cog):
def __init__(self,client):
self.client = client
self.eSantaLogo = discord.File("resources\embedImages\eSanta.png", filename="eSanta.png")
@commands.group(aliases=["help","commands"], invoke_without_command=True)
async def help_(self,ctx):
prefix = ''.join(get_prefix(self.client, ctx))
embed=discord.Embed(title="eSanta Command Groups",
url="https://esanta.me",
color=discord.Color.dark_purple(),
timestamp=datetime.datetime.now(),
description=f'Current server prefix: {prefix}')
embed.set_thumbnail(url='attachment://eSanta.png')
embed.set_footer(text=f"Requested by {ctx.author.name}")
embed.add_field(name='**Categories**',value=f"{prefix}help moderator\n{prefix}help fun", inline=True)
await ctx.send(file=self.eSantaLogo,embed=embed)
def setup(client):
client.add_cog(Help(client))
當我第一次運行它時,它完全正常。

但是當我嘗試再次運行它時,會引發此例外。
Traceback (most recent call last):
File "C:\Users\notri\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "E:\bot\bot.py", line 104, in on_command_error
raise error
File "C:\Users\notri\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\notri\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 1353, in invoke
await super().invoke(ctx)
File "C:\Users\notri\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\notri\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ValueError: I/O operation on closed file
uj5u.com熱心網友回復:
從檔案中:
檔案物件是一次性使用的,并不意味著可以在多個
abc.Messageable.send()s.
您應該在發送檔案后重新加載檔案,這是一個很好的解決方案:
class Help(commands.Cog):
def __init__(self,client):
self.client = client
@property
def eSantaLogo(self):
return discord.File("resources\embedImages\eSanta.png", filename="eSanta.png")
@commands.group(aliases=["help","commands"], invoke_without_command=True)
async def help_(self,ctx):
prefix = ''.join(get_prefix(self.client, ctx))
embed=discord.Embed(title="eSanta Command Groups",
url="https://esanta.me",
color=discord.Color.dark_purple(),
timestamp=datetime.datetime.now(),
description=f'Current server prefix: {prefix}')
embed.set_thumbnail(url='attachment://eSanta.png')
embed.set_footer(text=f"Requested by {ctx.author.name}")
embed.add_field(name='**Categories**',value=f"{prefix}help moderator\n{prefix}help fun", inline=True)
await ctx.send(file=self.eSantaLogo,embed=embed)
默認設定(客戶端):client.add_cog(幫助(客戶端))
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/420074.html
標籤:
上一篇:使用subprocess.call時,Python3未按所需順序列印輸出
下一篇:從日期時間獲取當前日期作為紀元
