如何“检查”该频道是否为私人频道?

时间:2018-10-13 04:01:02

标签: python python-3.x discord discord.py discord.py-rewrite

如何在discord.py rewrite中“检查”频道是否为私有频道, 我什至看到了类似的问题,但是答案不起作用:<< / p>

2 个答案:

答案 0 :(得分:1)

检查通道是否是PrivateChannel抽象基类的实例:

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")

答案 1 :(得分:-1)

我遇到了同样的问题,并像这样解决了。 :)

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