【发布时间】:2022-01-10 11:36:51
【问题描述】:
我正在使用 discord.py 开发一个机器人,但我有一个无法解决的错误。我不认为后者来自 discord.py 而是来自 python(我是这方面的新手)
我的问题: 我在“如果”中测试第一个条件。 如果这是真的,我会用另一个“如果”来测试其他条件。 另一方面,如果第一个“if”返回 false,我用“else”测试其他条件,然后在这个条件中使用“if”。
在我的第一个“if”中,如果为真,所有后续的“if”语句都会被执行,即使它们不应该执行。我对 else 中的“if”也有同样的问题。
一个shema:
if ...:
if ...:
...
if ...:
...
else:
if ...:
...
if ...:
...
我的真实代码:
@commands.command()
async def help(self, ctx, categorie = None)
if categorie == None:
await ctx.send(f"Mon préfixe sur ce serveur: `{pref}`\n\nSur quelle partie du bot voulez vous de l'aide ?\n`utile` | `fun` | `recherches` | `moderation` | `creator`")
def checkMessage(message):
return message.author == ctx.message.author and ctx.message.channel == message.channel
partie = await self.client.wait_for("message", timeout = 20, check = checkMessage)
if partie.content == "moderation" or partie.content == "Moderation":
await ctx.send(embed=modembed)
if partie.content == "utile" or partie.content == "Utile":
await ctx.send(embed=utileembed)
if partie.content == "fun" or partie.content == "Fun":
await ctx.send(embed=funembed)
if partie.content == "recherches" or partie.content == "Recherches":
await ctx.send(embed=recherchesembed)
if partie.content == "creator" or "Creator":
creatorembed.set_thumbnail(url="https://zupimages.net/up/20/52/qpa0.png")
await ctx.send(embed=creatorembed)
else:
if categorie == "moderation" or "Moderation" or "mod":
await ctx.send(embed=modembed)
if categorie == "utile" or "Utile" or "util":
await ctx.send(embed=utileembed)
if categorie == "fun" or "Fun":
await ctx.send(embed=funembed)
if categorie == "recherches" or "recherche" or "Recherches" or "Recherche" or "rech" or "Rech":
await ctx.send(embed=recherchesembed)
if categorie == "creator" or "Creator":
creatorembed.set_thumbnail(url="https://zupimages.net/up/20/52/qpa0.png")
await ctx.send(embed=creatorembed)
【问题讨论】:
标签: python if-statement discord.py conditional-statements