D
D
Dream2021-05-19 19:30:14
Python
Dream, 2021-05-19 19:30:14

How do I prevent a bot from replying to private messages on Discord?

I want to make it so that only the bot can write to the server member, and the server member itself cannot. Those. the bot did not respond to commands in private messages, only on the server. How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2021-05-20
@dreameddd

Add a check for command execution in the LAN.
Or for the whole bot:
https://discordpy.readthedocs.io/en/stable/ext/com...

@bot.check
async def global_guild_only(ctx):
    if not ctx.guild:
        raise commands.NoPrivateMessage  # replicating guild_only check: https://github.com/Rapptz/discord.py/blob/42a538edda79f92a26afe0ac902b45c1ea20154d/discord/ext/commands/core.py#L1832-L1846
    return True

Or for each command separately:
https://discordpy.readthedocs.io/en/stable/ext/com...
@bot.command()
@commands.guild_only()
async def cmd(ctx, ...):
    """Here we go..."""
    ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question