Daantz
Daantz

Reputation: 41

How can I "check" if the channel is private?

How can I "check" if the channel is private in discord.py rewrite, I even saw a similar question but the answer was not working :<

Upvotes: 3

Views: 3111

Answers (2)

Kevin Bose
Kevin Bose

Reputation: 21

I had the same problem and solve it like this. :)

@bot.event
async def on_message(message):
    if str(message.channel.type) == "private":
        print("message is privat...")
    else:
        print("message is not private...") 

Upvotes: 1

Patrick Haugh
Patrick Haugh

Reputation: 60984

Check if the channel is an instance of the PrivateChannel abstract base class:

from discord.abc import PrivateChannel
from discord.ext.commands import Bot    

bot = Bot(command_prefix='!')

@bot.command()
async def isprivate(ctx):
    await ctx.send(isinstance(ctx.channel, PrivateChannel))

bot.run("token")

Upvotes: 2

Related Questions