I have a question, in my code i get an error: TypeError: export() got an unexpected keyword argument 'set_timezone'
And i really dont know how to fix it. I want to archive a channel in discord with using discord.py
and the module chat_exporter. But there is a TypeError within the set timezone
.
Here is the code:
@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)
And that is the console log
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'
Can please anyone help me?
CodePudding user response:
TypeError: func() got an unexpected keyword argument 'x'
means that you've passed a keyword to the function which isn't in the parameters of the function. In your case it's set_timezone
.
If you look at the function definition, you can see there's no kwarg called set_timezone
:
async def export(
channel: discord.TextChannel,
limit: Optional[int] = None,
tz_info="UTC",
guild: Optional[discord.Guild] = None,
):
Instead it's tz_info
. So, for your code:
transcript = await chat_exporter.export(channel, tz_info="UTC")
For UTC
you don't even need to pass a value for tz_info
, because the default value is already UTC
.
CodePudding user response:
How i see from documentation:
Optional Argument(s): limit: Integer value to set the limit (amount of messages) the chat exporter gathers when grabbing the history (default=unlimited). tz_info: String value of a TZ Database name to set a custom timezone for the exported messages (default=UTC) military_time: Boolean value to set a 24h format for times within your exported chat (default=False | 12h format) bot: commands.Bot object to gather members who are no longer in your guild.
example:
@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,
)
So may be you should use tz_info
instead of set_timezone
?