I want to check if the user ran the command in the server or in DM’s and after that, I want it to stop, but if the user ran the command in a server then I want it to run.
@client.command(name=’dm’, aliases=[‘message’, ‘send’])
async def dm(ctx, user: discord.User, *, message: str):
try:
await user.send(message)
sent_message = await ctx.send(f’Message sent to {user.name}’)
await asyncio.sleep(1)
await ctx.message.delete() <– Don’t want this to get ran because the bot can’t delete the user’s
await asyncio.sleep(0) message as it does in servers.
await sent_message.delete()
except discord.Forbidden:
await ctx.send(‘User doesn’t accept DM’s’)
await asyncio.sleep(1)
await ctx.message.delete() <– Don’t want this to get ran because the bot can’t delete the user’s
await asyncio.sleep(0) message as it does in servers.
await sent_message.delete()
XvL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.