【发布时间】:2021-10-21 09:01:30
【问题描述】:
async def transcript(self, ctx):
"""Creates a transcript for the channel the command is entered in
"""
if ctx.channel.category.name in self.bot.ticket_categories:
transcript = await chat_exporter.export(ctx.channel)
if transcript is None:
embed = discord.Embed(text="Transcript creation failed!",
color=0xDE3163)
await ctx.send(embed=embed)
return
transcript_file = discord.File(io.BytesIO(),
filename=f"transcript-{ctx.channel.name}.html")
embed = discord.Embed(title="Transcript creation successful!",
color=0x00A86B)
await ctx.send(embed=embed)
await ctx.send(file=discord.File(transcript_file, f"transcript-{ctx.channel.name}.html"))
我已经制作了一个 python discord 机器人,可以打印给定频道的成绩单。但是,当命令运行时,我收到以下错误。
Traceback (most recent call last):
File "C:\Users\amogh\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\amogh\Documents\GitHub\MiscBot\cogs\tickets.py", line 1613, in transcript
await ctx.send(file=transcript_file)
File "C:\Users\amogh\AppData\Local\Programs\Python\Python39\lib\site-packages\discord_components\dpy_overrides.py", line 371, in send_override
return await send(channel, *args, **kwargs)
File "C:\Users\amogh\AppData\Local\Programs\Python\Python39\lib\site-packages\discord_components\dpy_overrides.py", line 306, in send
data = await state.http.send_files(
File "C:\Users\amogh\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 187, in request
for params in form:
TypeError: 'FormData' object is not iterable
【问题讨论】:
-
你需要阅读它 self.fp = open(fp, 'rb').read()
-
这就是 discord.py 模块。
-
是的,我已经意识到了
标签: python python-3.x io discord.py typeerror