0
votes

I am trying to create a bot that will send to the DM user after rejecting the rules.

@client.event
async def on_reaction_add(reaction, user):
    regulamin_channel = client.get_channel(864135527963820032)
    if reaction.emoji == "????":
        Role = discord.utils.get(user.guild.roles, name="Member")
        Role2 = discord.utils.get(user.guild.roles, name="Apply")
        await user.add_roles(Role)
        await user.remove_roles(Role2)
    if reaction.emoji == "????":
        await user.send("You must accept the rules")

Unfortunately I am getting this error:

Ignoring exception in on_reaction_add Traceback (most recent call last): File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "E:\Moje rzeczy\BOT\bot.py", line 47, in on_reaction_add await user.send("You must accept the rules") NameError: name 'ClientUser' is not defined Ignoring exception in on_reaction_add Traceback (most recent call last): File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "E:\Moje rzeczy\BOT\bot.py", line 47, in on_reaction_add await user.send("You must accept the rules") File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\abc.py", line 1013, in send channel = await self._get_channel() File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 299, in _get_channel ch = await self.create_dm() File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 142, in general return await getattr(self._user, x)(*args, **kwargs) AttributeError: 'ClientUser' object has no attribute 'create_dm' Ignoring exception in on_reaction_add Traceback (most recent call last): File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "E:\Moje rzeczy\BOT\bot.py", line 47, in on_reaction_add await user.send("You must accept the rules") File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\abc.py", line 1013, in send channel = await self._get_channel() File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 299, in _get_channel ch = await self.create_dm() File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 142, in general return await getattr(self._user, x)(*args, **kwargs) AttributeError: 'ClientUser' object has no attribute 'create_dm' Ignoring exception in on_reaction_add Traceback (most recent call last): File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "E:\Moje rzeczy\BOT\bot.py", line 47, in on_reaction_add await user.send("You must accept the rules") File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\abc.py", line 1013, in send channel = await self._get_channel() File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 299, in _get_channel ch = await self.create_dm() File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 142, in general return await getattr(self._user, x)(*args, **kwargs) AttributeError: 'ClientUser' object has no attribute 'create_dm' Ignoring exception in on_reaction_add Traceback (most recent call last): File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "E:\Moje rzeczy\BOT\bot.py", line 47, in on_reaction_add await user.send("You must accept the rules") NameError: name 'ClientUser' is not defined Ignoring exception in on_reaction_add Traceback (most recent call last): File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "E:\Moje rzeczy\BOT\bot.py", line 47, in on_reaction_add await user.send("You must accept the rules") File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\abc.py", line 1013, in send channel = await self._get_channel() File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 299, in _get_channel ch = await self.create_dm() File "C:\Users\Mikołaj\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\member.py", line 142, in general return await getattr(self._user, x)(*args, **kwargs) AttributeError: 'ClientUser' object has no attribute 'create_dm'.

1
You should explain DM because this is a discord-specific abbreviation. Remember: Please always post the complete error-message (including files and lines numbers). This will help to locate the issue. Looking forward to your edit 😉️hc_dev

1 Answers

0
votes

Method .send() is not on ClientUser which is passed to function as user, in docs this is ClientUser https://discordpy.readthedocs.io/en/stable/api.html#clientuser

But you need to get a User object to be passed to function or get it somewhere https://discordpy.readthedocs.io/en/stable/api.html#discord.User