I'd like to know how to dm a specific person that will always be the same. I've tried many StackOverFlow posts and the official discord.py documentation but none of them worked. I have discord.py 1.7.3. So far I've got the following:
import discord
from discord.ext import commands
@client.command()
async def dm(ctx):
user = client.get_user(1234567891011) # <- This user will always be the same.
await user.send("Hi")
When I type the command in the server the following exception appears:
Ignoring exception in command dm:
Traceback (most recent call last):
File "C:\Users\myuser\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\myuser\Documents\Python Scripts\Bot\main.py", line 110, in dm await user.send("Hola")
AttributeError: 'NoneType' object has no attribute 'send'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\myuser\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\myuser\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'send'