discord.py TextChannel.edit()返回TypeError

2024-09-29 19:24:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个bot命令的代码,该命令在通道上设置自定义slowmode:

if message.author.permissions_in(message.channel).manage_channels:
    if slowmode > 21600:
        await ctx.send('The maximum possible slowmode is 21600, or 6 hours.')
    elif slowmode < 0:
        await ctx.send('The minimum possible slowmode is 0, or no slowmode.')
    else:
        try:
            await ctx.message.channel.edit(reason='setcustomslowmode', slowmode_delay=slowmode)
            await ctx.send(f'Set the slowmode of channel <#{ctx.message.channel.id}> to **{slowmode}** seconds.')
        except discord.Errors.Forbidden:
            await ctx.send("I'm not allowed to do that, update my permissions and try again.")
else:
    await ctx.send('You need the permission `manage channel` to do this!')

它返回此回溯:

Ignoring exception in on_message
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/discord/client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "discordbot.py", line 1212, in on_message
    await message.channel.edit(reason='Eric Bot /setcustomslowmode', slowmode_delay=int(subcommand[0]))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/discord/channel.py", line 235, in edit
    await self._edit(options, reason=reason)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/discord/abc.py", line 285, in _edit
    self._update(self.guild, data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/discord/channel.py", line 131, in _update
    self._fill_overwrites(data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/discord/abc.py", line 294, in _fill_overwrites
    self._overwrites.append(_Overwrites(id=overridden_id, **overridden))
TypeError: __new__() got an unexpected keyword argument 'allow_new'

编辑频道的代码工作正常(slowmode已正确更改),但随后声明slowmode已成功更改的通知从未发送

我已经尝试将reason=参数删除为edit(),但它只是默默地更改slowmode并引发异常,就像以前一样

This没有提到任何有关错误的信息,看起来我正确地使用了该函数

我做错了什么


Tags: inpysendmessagelinelibrarychannelawait

热门问题