How to make a discord.py bot private/direct message someone who's not the author?
Solution 1
It's actually simpler than that
@bot.command(pass_context=True)
async def poke(ctx, member: discord.Member):
await bot.send_message(member, 'boop')
send_message
contains logic for private messages, so you don't have to use start_private_message
yourself. The : discord.Member
is called a converter, and is described in the documentation here
Solution 2
I might be necroing this post a bit, but the recent version of this would look like this:
@bot.command():
async def poke(ctx, user: discord.Member=None):
if user is None:
await ctx.send("Incorrect Syntax:\nUsage: `!poke [user]`")
await user.send("boop")
The if user is None:
block is optional, but is useful if you want to have an error message if a command isn't used correctly.
GooeyGreenMuffins
Updated on August 01, 2022Comments
-
GooeyGreenMuffins almost 2 years
Say I want to make a bot with a "poke" feature (aka sends a pm to a user saying "Boop" when someone says "!poke @user#0000"), how would I do this? It works perfectly when I do this:
@bot.command(pass_context=True) async def poke(ctx, message): await client.send_message(ctx.message.author, 'boop')
but only if I want to poke the author of the message. I want to poke whoever's being @'d.
I know the discord.py documents say I can use this:
start_private_message(user)
but I don't know what to put in place of user.