Reputation: 112
I want to create a command that only works if a user is DMing their command. How do I do that? I am using discord.py 1.5.1, and I'm fairly new to discord.py. Here is my code so far:
from discord.ext import commands, tasks
import discord
intents = discord.Intents.all
bot = commands.Bot(command_prefix='$', description='- shows this message', intents=intents)
---- snip ----
@commands.command(brief='a DM command')
async def dm_command(ctx):
# do stuff here
bot.run('TOKEN')
When I try DMing the command, the bot doesn't pick up the DM I sent. Should I specify the command in on_message()?
Upvotes: 0
Views: 5668
Reputation: 1
@client.command()
async def dm(ctx):
await ctx.author.send('Hi im a discord bot!')#this is the message that will pop up in ur dms when u input the cmd
client.run('Token')
Upvotes: 0
Reputation: 468
Here is my code for your query:
@bot.command()
async def dm_command(ctx):
if isinstance(ctx.channel, discord.channel.DMChannel):
#do stuff here
First of all, the decorator you use is not what I was taught when i first learned discord.py, so I changed the decorator from @commands.command(brief='a DM command')
to @bot.command()
(Feel free to change back if it works for you). Then, the rest is fairly simple. I just checked if the channel was a DM channel, and thats it! If you have any questions about my code or if you have unforseen errors, follow up!
Upvotes: 2