为什么我的 discord.py 代码中有这个错误
Why i've this error in my discord.py code
我正在使用 discord.py 开发一个机器人,但我有一个无法解决的错误。我不认为后者来自discord.py而是来自python(我是这方面的新手)
我的问题:
我在“如果”中测试第一个条件。
如果这是真的,我用另一个“如果”测试其他条件。
另一方面,如果第一个“if”returns false,我用“else”测试其他条件,然后在这个条件中使用“if”。
在我的第一个“if”中,如果为真,所有后续的“if”语句都会执行,即使它们不应该执行。我对 else 中的“if”有同样的问题。
一个架构:
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)
它return我:
你的逻辑有误:
if categorie == "moderation" or "Moderation" or "mod":
此条件始终为真。替换为
if categorie in ("moderation", "Moderation", "mod"):
也为其他 if
操作员执行此操作。
但我建议您使用 discord.py 中的 HelpCommand
class 创建您的帮助命令。它更简单,是创建帮助命令的最佳方式。你可以阅读它 here.
我正在使用 discord.py 开发一个机器人,但我有一个无法解决的错误。我不认为后者来自discord.py而是来自python(我是这方面的新手)
我的问题: 我在“如果”中测试第一个条件。 如果这是真的,我用另一个“如果”测试其他条件。 另一方面,如果第一个“if”returns false,我用“else”测试其他条件,然后在这个条件中使用“if”。
在我的第一个“if”中,如果为真,所有后续的“if”语句都会执行,即使它们不应该执行。我对 else 中的“if”有同样的问题。
一个架构:
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)
它return我:
你的逻辑有误:
if categorie == "moderation" or "Moderation" or "mod":
此条件始终为真。替换为
if categorie in ("moderation", "Moderation", "mod"):
也为其他 if
操作员执行此操作。
但我建议您使用 discord.py 中的 HelpCommand
class 创建您的帮助命令。它更简单,是创建帮助命令的最佳方式。你可以阅读它 here.