Eric Jin
Eric Jin

Reputation: 3924

discord.py TextChannel.edit() returns TypeError

I have this code for a bot command that sets a custom slowmode on a channel:

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!')

It returns this traceback:

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'

The code that edits the channel works correctly (the slowmode is changed correctly), however the notification afterward stating that the slowmode was successfully changed never sends.

I've tried removing the reason= argument to edit(), but it just silently changes the slowmode and raises an exception, just like before.

This doesn't mention anything about the error and it looks like I am using the function correctly.

What am I doing wrong?

Upvotes: 0

Views: 269

Answers (1)

ravexu
ravexu

Reputation: 665

You need to update your discord library version. This error has been fixed. Update to version 1.3.4 and error will be fixed.

python -m pip install -U discord.py

Upvotes: 1

Related Questions