乍一看,这可能是因为您没有参数的默认值。另外,我认为您应该开始使用特定于命令的错误处理。
您可以在函数上方使用{command.name}.error 来仅处理来自该特定命令的错误。
下面我添加了一些东西和 cmets 来展示可能解决此问题的方法。
#The below code bans player.
@bot.command()
@commands.has_permissions(ban_members = True)
async def ban(ctx, member : discord.Member = None, *, reason = None): # Adding "= None" to the end of parameters will tell the code that if someone who uses the command doesn't give a reason or a member, just set the values to None.
if member is None:
await ctx.send("⚠️ | Forgot Username")
if reason is None:
reason = "Adminban"
else:
reason = reason
# Funktionen für Nachrichten
embed = discord.Embed(title="? » Du wurdest ausgeschlossen!", description=f"Dein Account wurde so eben aus\nunserem Discord-Server ausgeschlossen.\n\n───────────────────────── \n? ** | DETAILS ZU DEINER SPERRUNG..**\n Hier siehst du nun einige Details zu deiner Sperrung.\nDieses dienen sowohl als Info für dich, als auch für uns.\n\n┏?♂️〢**Gesperrt von:** `{ctx.author}`\n┗?〢**Grund:** `{reason}`\n\n───────────────────────── \n**? » Du möchtest wieder auf unseren Server?**\nDann fülle dieses Formular aus:** https://bl4cklist.de/unban **", color=0xf04747)
embed.set_thumbnail(url="https://i.imgur.com/4np2bdK.png")
embed.set_footer(text=f"BL4CKLIST.DE?GAMING | Discord-Server", icon_url="https://i.imgur.com/4np2bdK.png")
embed.set_image(url="https://i.imgur.com/Ua2y6oF.png")
response = choice([
'https://media1.giphy.com/media/9jCTfM9QIzPLqAwkE9/giphy.gif',
'https://media4.giphy.com/media/lY26OFBfrFFeecJEtT/giphy.gif',
'https://media4.giphy.com/media/Q4Eu7AZO4FY14FMnTo/giphy.gif',
'https://media3.giphy.com/media/BSdqZU7F0eRlXtAsPp/giphy.gif'
])
embed1 = discord.Embed(title=f"? » {member.name} wurde gesperrt!", description=f"Genaue Informationen zu der Sperrung:\n\n┏?♂️〢**Ausgeschlossen von:** `{ctx.author}`\n┗?〢**Grund der Sperrung:** `{reason}`", color=0xe74c3c)
embed1.set_thumbnail(url=f"{member.avatar_url}")
embed1.set_footer(text=f"BL4CKLIST.DE?GAMING | Discord-Server", icon_url="https://i.imgur.com/4np2bdK.png")
embed1.set_image(url=f"{response}")
embed2 = discord.Embed(title="? » Ein Mitglied wurde gesperrt!", description=f"Hier siehst du nun einige Details zur Sperrung.\n─────────────────────────\n\n» **Grund der Sperrung:** `{reason}`\n» **Name des Users:** `{member}`\n» **ID des Gesperrten:** `{member.id}`\n\n─────────────────────────", color=0xf04747)
embed2.set_thumbnail(url=f"{member.avatar_url}")
embed2.set_footer(text=f"BL4CKLIST.DE?GAMING | Discord-Server", icon_url="https://i.imgur.com/4np2bdK.png")
channel = bot.get_channel(755014990465073306)
# Funktionen für Nachrichten
await member.send(embed=embed)
await member.ban(reason=reason)
await ctx.send(embed=embed1)
await channel.send(embed=embed2)
# This part will track the errors specifically for the ban command only, and in this case, will print out the error
@ban.error
async def ban_error(ctx, error):
print (error)