首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError: export()得到一个意外的关键字参数'set_timezone‘

TypeError: export()得到一个意外的关键字参数'set_timezone‘
EN

Stack Overflow用户
提问于 2022-08-10 13:38:38
回答 2查看 259关注 0票数 -1

我有一个问题,在我的代码中我得到了一个错误:TypeError: export() got an unexpected keyword argument 'set_timezone'和我真的不知道如何修复它。我想存档一个与使用discord.py和模块出口商不一致的通道。但是在TypeError中有一个set timezone

以下是代码:

代码语言:javascript
复制
@client.command()
@commands.has_role(MANAGEMENT_ROLE_ID)
async def archive(channel, archive_channel):
        if channel and archive_channel:
            transcript = await chat_exporter.export(channel, set_timezone='UTC')
            transcript_file = discord.File(io.BytesIO(transcript.encode()), filename=f"{channel.name}.html")
            await archive_channel.send(file=transcript_file)

这就是控制台日志

代码语言:javascript
复制
Ignoring exception in command archive:
Traceback (most recent call last):
  File "C:\Users\Jonas\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "d:\Discord\discord Bots\derzockereckenbot 2.0\main.py", line 134, in archive
    transcript = await chat_exporter.export(channel, set_timezone='UTC')
TypeError: export() got an unexpected keyword argument 'set_timezone'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Jonas\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Jonas\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Jonas\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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: TypeError: export() got an unexpected keyword argument 'set_timezone'

有人能帮我吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-08-10 13:46:34

TypeError: func() got an unexpected keyword argument 'x'意味着您已经向函数传递了一个关键字,该关键字不在函数的参数中。在你的例子中,它是set_timezone

如果你看一下函数定义,你会发现没有一个叫做set_timezone的kwarg

代码语言:javascript
复制
async def export(
    channel: discord.TextChannel,
    limit: Optional[int] = None,
    tz_info="UTC",
    guild: Optional[discord.Guild] = None,
):

取而代之的是tz_info。因此,对于您的代码:

代码语言:javascript
复制
transcript = await chat_exporter.export(channel, tz_info="UTC")

对于UTC,您甚至不需要为tz_info传递一个值,因为默认值已经是UTC

票数 0
EN

Stack Overflow用户

发布于 2022-08-10 13:44:31

我如何从文档中看到:

可选参数(S):极限:整数值,用于设置聊天导出程序获取历史记录(default=unlimited)时收集的限制(消息数量)。tz_info: TZ数据库名的字符串值,用于为导出的消息(default=UTC)、 military_time:布尔值设置自定义时区,以设置24小时格式,用于在导出的聊天(default=False /12小时格式) bot: commands.Bot对象中收集不再在您的公会中的成员。

示例:

代码语言:javascript
复制
@bot.command()
async def save(ctx: commands.Context, limit: int, tz_info: str, military_time: bool):
    transcript = await chat_exporter.export(
        ctx.channel,
        limit=limit,
        tz_info=tz_info,
        military_time=military_time
        bot=bot,
    )

因此,您应该使用tz_info 而不是 set_timezone**?**

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73307348

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档