0

I want to know that to get the user who send dm, the idea is to stop people using the bot in dm and then ping them in #bot-lab so that they can use it there

i havn't tried anything yet, but would begreat if anyone tell me how to do

thank you

  • 2
    did you google it? took me 10 seconds to find an answer. `isinstance(ctx.channel, discord.channel.DMChannel)` can tell you if a message comes from [DM](https://stackoverflow.com/questions/58987677/discord-py-check-if-channel-is-a-dm) or not. –  Jul 22 '21 at 16:51
  • indeed yes, i did google that but didn't get right answer, glad you got, post the answer, i'll mark it correct – Hardik Kumar Sinha Jul 22 '21 at 16:55
  • 1
    Exactly what search term did you use? The suggestion (which I have now linked as a duplicate) came up for me as the [first result](https://duckduckgo.com/?q=discord.py+check+if+message+is+from+dm) for `discord.py check if message is from dm`, which seems to me like the most obvious thing to try. – Karl Knechtel Jul 22 '21 at 17:25

1 Answers1

2

In discord.py you can use the isinstance(ctx.channel, discord.channel.DMChannel) to check if a message is a DM or not.

@client.command()
async def check(ctx, arg):
    if isinstance(ctx.channel, discord.channel.DMChannel):
        await ctx.send(arg)