You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用discord.py与chat_exporter导出频道时遇TypeError:set_timezone参数异常

解决chat_exporter的TypeError: export() got an unexpected keyword argument 'set_timezone'问题

错误原因

你遇到的错误是因为当前安装的chat-exporter版本不支持set_timezone参数——该参数在新版本中已被重命名为timezone,或者你的版本过旧根本没有时区配置功能。

修复步骤

1. 升级chat-exporter到最新版本

执行以下命令升级依赖,确保使用支持时区配置的最新版本:

pip install --upgrade chat-exporter

2. 修改代码中的参数名

将原代码里的set_timezone='UTC'替换为timezone='UTC',修改后的完整代码如下:

import io
import discord
from discord.ext import commands
from chat_exporter import export

MANAGEMENT_ROLE_ID = # 替换为你的管理角色ID

@client.command()
@commands.has_role(MANAGEMENT_ROLE_ID)
async def archive(channel, archive_channel):
        if channel and archive_channel:
            transcript = await export(channel, timezone='UTC')
            transcript_file = discord.File(io.BytesIO(transcript.encode()), filename=f"{channel.name}.html")
            await archive_channel.send(file=transcript_file)

3. 验证修复

重启Discord机器人后执行archive命令,此时参数错误应该会消失。

如果升级后仍有问题,可查看对应版本的chat-exporter文档,确认时区配置的正确参数名。

内容的提问来源于stack exchange,提问作者Joniii11

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 00:15:58