Vusal Ismayilov
Vusal Ismayilov

Reputation: 15

Discord.py Send a DM to a Custom ID User

I am using discord.py, and want to send a custom DM to a custom user with an ID of my wish. I have literally tried every way and option we had on both Stack Overflow, and discord.py, however, none of them ended up to be working. The result that I get is always None. Any suggestions?

What I have tried:

#1
    user = await bot.get_user_info(user_id)
    await user.send('hello')
#2
    await client.send_message(discord.Object(id='12324234183172'), 'hello')
#3

    async def send_dm(ctx, member: discord.Member, *, content):
        channel = await member.create_dm()
        await channel.send(content)

Upvotes: 0

Views: 550

Answers (1)

Shunya
Shunya

Reputation: 2449

Make sure you are using the discord.py rewrite branch, as that one is the most up-to-date version of discord.py. All the three ways you are trying to send a direct message are not working as of discord.py-rewrite. If you are using the rewrite branch, you can update any of these three methods:

In #1 the problem is that the method Client.get_user_info() was changed to Client.fetch_user(), which should retrieve you the correct user.

In #2 the problem is that the method Client.send_message() was changed to channel.send()

The way of handling DMs in #3 is currently not used although it should be still valid. I recommend you to simply member.send() to send a direct message to a user.

Another important thing is that the bot cannot send DM to users that do not share guilds with the bot, so make sure that user is in the guild where the bot is running.

References:

Upvotes: 1

Related Questions