【发布时间】:2020-12-17 23:44:37
【问题描述】:
我使用一个命令来检查我的机器人在哪个频道中。如果它在频道中,那么一切都会很好地输出。但如果机器人不在频道中,我会得到控制台条目:AttributeError: 'NoneType' object has no attribute 'channel'。我的代码如下所示:
@commands.command()
@commands.is_owner()
async def channel(self, ctx):
bot_channel = ctx.guild.voice_client.channel
await ctx.send(embed=discord.Embed(
title=f":eyes: Ich befinde mich hier: {bot_channel}",
color=self.bot.get_embed_color(ctx.guild)))
if bot_channel is None:
await ctx.message.add_reaction("❌")
这是关于if bot_channel is None的下部。这里什么都没有发生,只有输出显示在控制台中。这里的正确方法是什么?
【问题讨论】:
标签: python discord bots discord.py