How can I get my discord bot to DM a member and myself?

geliebt picture geliebt · Dec 23, 2019 · Viewed 12.1k times · Source

How, if possible, would I get my discord bot (in python) to DM another user and whoever sent the command (telling them what they said)?

Edit: Solved, thanks Patrick Haugh - https://stackoverflow.com/users/6779307/patrick-haugh btw here's my code i have in case anyone else has the same problem:

@client.command()
async def dm(ctx, user: discord.User, *, message=None):
    if message == None:
        await ctx.send('You need to put a message')
    else:
        await user.send(message)
        await ctx.channel.purge(limit=1)
        await ctx.send('DM Sent')
        await ctx.author.send('"' + message + '"' + ' sent to ' + str(user))
        # just so i can see every dm (a bit creepy ik but hey it's my bot so i'll do it)
        print('"' + message + '"' + ' sent to ' + str(user))

Answer

Laurent picture Laurent · Dec 23, 2019

The following code snippet should answer your question:

async def on_message(self, message):
    await message.author.send("Content")
    await client.get_user(other_user_id).send("Content")