Reputation: 926
Yesterday, my code was perfectly fine. Everything was running... and it was going great. All of a sudden, this error:
TypeError: __new__() got an unexpected keyword argument 'deny_new'
pops up in my PyCharm console. I've looked it up on the internet but I've only found a similiar questions with zero answers to it. I hope the stackoverflow community will be able to help me. I did not change my code, all I did was, I tried to host my bot on heroku, and it did not go well. And after my first few attempts, I gave up. But, I found out my bot started going crazy and I couldn't run it anymore :<. Has anyone else experienced this and know how to fix it? UPDATE I just found out that for some reason, it only works on my test server but not any other servers.
Traceback (most recent call last):
File "C:/Users/danie/PyCharmProjects/skybot/skybotgaming.py", line 21, in <module>
client.run('TOKEN')
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\client.py", line 640, in run
return future.result()
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\client.py", line 621, in runner
await self.start(*args, **kwargs)
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\client.py", line 585, in start
await self.connect(reconnect=reconnect)
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\client.py", line 499, in connect
await self._connect()
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\client.py", line 463, in _connect
await self.ws.poll_event()
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\gateway.py", line 471, in poll_event
await self.received_message(msg)
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\gateway.py", line 425, in received_message
func(data)
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\state.py", line 750, in parse_guild_create
guild = self._get_create_guild(data)
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\state.py", line 725, in _get_create_guild
guild._from_data(data)
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\guild.py", line 297, in _from_data
self._sync(guild)
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\guild.py", line 328, in _sync
self._add_channel(CategoryChannel(guild=self, data=c, state=self._state))
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\channel.py", line 726, in __init__
self._update(guild, data)
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\site-packages\discord\channel.py", line 737, in _update
self._fill_overwrites(data)
File "C:\Users\danie\anaconda3\envs\discordbottest\lib\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 'deny_new'
I tried it with a different file and bot and I got the same results, this is like a problem with discord.py. This is literally my entire code
import discord
import random
from discord.ext import commands
import asyncio
client = commands.Bot(command_prefix='{')
client.remove_command('help')
@client.event
async def on_ready():
print("Signed in")
@client.command()
async def dm(ctx):
await ctx.author.send("What up chump?")
client.run('TOKEN')
Upvotes: 58
Views: 31602
Reputation: 754
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.
Upvotes: 3
Reputation: 11
I think you may be experiencing the same issue as I was. I had "discord" installed instead of "discord.py". I was able to change my requirements.txt to use "discord.py" instead of "discord".
discord.py==1.3.4
Upvotes: 1
Reputation: 101
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
Upvotes: 5
Reputation: 2281
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.
Upvotes: 6
Reputation: 1606
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.
Upvotes: 71