我正在创建一个命令,我只想通过机器人的 DM 执行该命令。当前代码可以将命令发送到任何 channel ,我想防止这种情况。
@client.command()
async def check(ctx, arg):
if discord.ChannelType.private:
await ctx.send(arg)
我也试过: discord.ChannelType == discord.ChannelType.private & discord.DMChannel
最佳答案
在 discord.py 中,直接消息 channel 对象来自 class discord.channel.DMChannel
.我们可以使用 isinstance()
检查一个对象是否来自一个类:
@client.command()
async def check(ctx, arg):
if isinstance(ctx.channel, discord.channel.DMChannel):
await ctx.send(arg)
关于python - Discord.py 检查 Channel 是否为 DM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58987677/