Discord.py error: TypeError: __new__() got an unexpected keyword argument 'deny_new'

Solution 1:

Discord pushed a new change that changes the overwrites object.

Just reinstall the latest version of Discord.py

python3 -m pip install -U discord.py

That's it.

Solution 2:

An alternate option, if you are stuck with an older version of discord.py and would rather not have to update 10k+ lines of code right now, is the following quick and dirty patch I came up with based on this commit:

--- channel.py.old  2017-02-27 15:02:23.000000000 -0800
+++ channel.py  2020-07-22 02:44:03.000000000 -0700
@@ -27,13 +27,28 @@
 from . import utils
 from .permissions import Permissions, PermissionOverwrite
 from .enums import ChannelType
-from collections import namedtuple
 from .mixins import Hashable
 from .role import Role
 from .user import User
 from .member import Member
 
-Overwrites = namedtuple('Overwrites', 'id allow deny type')
+class Overwrites:
+    __slots__ = ('id', 'allow', 'deny', 'type')
+
+    def __init__(self, **kwargs):
+        self.id = kwargs.pop('id')
+        self.allow = kwargs.pop('allow', 0)
+        self.deny = kwargs.pop('deny', 0)
+        self.type = kwargs.pop('type')
+
+    def _asdict(self):
+        return {
+            'id': self.id,
+            'allow': self.allow,
+            'deny': self.deny,
+            'type': self.type,
+        }
+
 
 class Channel(Hashable):
     """Represents a Discord server channel.

(note: this is diff'd against discord.py 0.16.7. It may be slightly different depending on what version of discord.py you're running.)

I must stress that this is a hack at best, and there are no guarantees as to how long this will continue to work. Furthermore, there are no guarantees that Discord won't suddenly introduce some other random API change that will break older discord.py in new and interesting ways. You (like I) should really update your code to comply with the newer discord.py. I only present this workaround as I suspect you are in the same situation as me (having things suddenly break and needing to get things back up and running RIGHT NOW but not having the time to quickly update 10k+ lines of code to fix this.

Solution 3:

I just had this issue and just now fixed it, and here is what I did (this worked for my laptop running Windows):

pip uninstall discord.py
pip install discord.py
py -3 -m pip install -U discord.py

I also am running a discord bot on a Raspberry Pi and this is how I fixed it:

pip uninstall discord.py
pip install discord.py
python3 -m pip install -U discord.py

Solution 4:

I want to clarify the answer. On a raspberry pi, I somehow had discord.py installed for user pi and for root - and they were different versions in different places. This caused me a lot of confusion; I had no idea I had two copies, and I have no idea how to get down to just 1, which I'd prefer. But the commands that get it working for root are:

sudo -i
pip3 uninstall discord.py
pip3 install discord.py
python3 -m pip install -U discord.py

Then and only then could I run my discord bot from /etc/rc.local, and for that to work I had to do this in /etc/rc.local:

(sleep 30; python3 /home/pi/applications/myBot.py &) &

For whatever reason, the usual suggestion of sleep 10 did NOT work, and this is on a pi 4 with not a lot else going on at startup.