python - discord py - Why doesn't my ban command work?
问题描述
I would like to create a ban command with features such as embed answers, a log function and dm-ing the user when they're banned.
For some reason, my ban command does not run. Nothing happens when the command is executed and if member is None
does not work for me either.
I have posted my code in the link provided: https://hastebin.com/ubayatiqey.py
Why doesn't my bot answer my =ban
command? Could I catch an error to fix it? Also, why don't Lines 41 to 48 not work as I expect them to?
解决方案
在浏览了您的代码后,我注意到了一些事情。首先,您试图打印error
这似乎是一个从未在您的代码中定义的变量。如果您想在出现错误时打印错误,我建议您为 ban 命令创建一个错误处理程序。其次,您正在尝试使用member
和reason
作为可选参数,虽然它们从未设置为可选参数,但我建议也更改它。我还注意到您正在尝试使用意图,我无法验证您是否启用了意图的天气,但您需要从 Discord Developers Portal 启用它们。我想说你应该尝试不带意图地运行代码,或者在 Discord 开发者门户中启用它们。如果这不能解决您的问题,请告诉我。如果您希望我进行所有更改,您可以复制此代码并将其粘贴到您的 IDE 中。:
@bot.command()
@commands.has_permissions(ban_members = True)
async def ban(ctx, member : discord.Member=None, *, reason=None):
if member is None:
await ctx.send("⚠️ | Forgot Username")
return
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.DEGAMING | 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.DEGAMING | 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.DEGAMING | 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)
# Error handler
@ban.error()
async def ban_error(ctx, error):
if isinstance(error):
print(error)
推荐阅读
- javascript - 如何使用 d3 使用 javascript 可视化本地 csv 文件?
- php - Codeigniter 应用程序中大量 mpdf 事务的服务器超时
- java - 使用名称创建 bean 时出错:注入自动装配的依赖项失败,无法解析占位符
- apache - 在 solr 服务器重新启动时丢失 solr 数据
- node.js - 使用 Mocha 对在 AMQP 消息接收事件时应触发的回调进行集成测试
- python - 使用“SearchFilter”时,尝试搜索时出现错误
- visual-c++ - 使用构造函数在类中初始化字符串
- groovy - Katalon Studio 从其他自定义关键字调用自定义关键字
- google-drive-api - google drive API的测试环境?
- vb.net - 使用第二种形式作为“请稍候......”-信息:奇怪的外观