【问题标题】:TypeError: expected str, bytes or os.PathLike object, not FileTypeError:预期的 str、字节或 os.PathLike 对象,而不是 File
【发布时间】: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


【解决方案1】:

transcript_file 已经是discord.File,用另一个discord.File 包裹它的目的是什么?您只需发送transcript_file 变量即可。

await ctx.send(file=transcript_file)

【讨论】:

  • 试过了,它返回了一个新的错误。我已经更新了我的代码和错误。请看一下。
猜你喜欢
  • 2021-03-05
  • 2017-10-23
  • 2020-07-12
  • 2019-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-27
相关资源
最近更新 更多