Ask coding questions

← Back to all posts
How do I close a discord bots dms
DrSovietSoviet (0)

Recently my bot has been used by people it's not supposed to be used by via dms how would I disable it's dms as a quick work around?

Answered by InvisibleOne (3186) [earned 5 cycles]
View Answer
InvisibleOne (3186)

If you are using commands you can use


or you can check if there is a server on the message

async def on_message(message):
  if not message.server:
xfinnbar (134)

Override the default on_message event and check if the channel is a DM before processing commands. If you are using bot instead of client for discordpy, then change client to bot:

@client.event # or bot if there is error
async def on_message(message):
if not isinstance(, discord.TextChannel):