我目前正在尝试制作一个能够使用户静音的不和谐机器人。到目前为止,我已经创建了此脚本,该脚本允许具有“ staff”角色的人员运行该命令,并为标记的用户提供“ Mute”角色。如果还不存在,它还会创建一个。问题是下面的代码不起作用。它在控制台中什么也没有说,但是如果您具有职员角色并运行命令,则不会发生任何事情。
@commands.has_role("staff")
async def mute(ctx, member: discord.Member=None):
guild = ctx.guild
if (not guild.has_role(name="Muted")):
perms = discord.Permissions(send_messages=False, speak=False)
await guild.create_role(name="Muted", permissions=perms)
role = discord.utils.get(ctx.guild.roles, name="Muted")
await member.add_roles(role)
print("? "+member+" was muted.")
if (not member):
await ctx.send("Please specify a member to mute")
return
@mute.error
async def mute_error(ctx, error):
if isinstance(error, commands.CheckFailure):
await ctx.send("You don't have the 'staff' role")
参考方案
此特定行:
print("? "+member+" was muted.")
在终端或运行命令的任何位置打印它。尝试await ctx.send
另外,如果您的Python版本> 3.6,请尝试使用f字符串。另外,您的错误是错误的。
@client.command()
@commands.has_role("staff")
async def mute(ctx, member: discord.Member):
role = discord.utils.get(ctx.guild.roles, name="Muted")
guild = ctx.guild
if role not in guild.roles:
perms = discord.Permissions(send_messages=False, speak=False)
await guild.create_role(name="Muted", permissions=perms)
await member.add_roles(role)
await ctx.send(f"?{member} was muted.")
else:
await member.add_roles(role)
await ctx.send(f"?{member} was muted.")
@mute.error
async def mute_error(ctx, error):
if isinstance(error, commands.MissingRole):
await ctx.send("You don't have the 'staff' role")
@mute.error
async def mute_error(ctx, error):
if isinstance(error, commands.BadArgument):
await ctx.send("That is not a valid member")
Discord.py重写自定义错误 - python我对编码非常陌生,我想知道如何在此处实现自定义错误,例如“缺少开发人员角色”: @bot.command() @commands.has_any_role("Temp.", "Owner") async def sh(ctx): await ctx.message.add_reaction(':true:50…
Python-crontab模块 - python我正在尝试在Linux OS(CentOS 7)上使用Python-crontab模块我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…
Discord.py重写所有命令的收集列表 - python我正在尝试获取Discord机器人中所有命令的列表以进行重写。我正在使用Python 3.6编写此我试图通过执行打印命令列表print(bot.commands)这仅为我提供以下回报:{<discord.ext.commands.core.Command object at 0x00000209EE6AD4E0>, <discord.ext…
Python Pandas导出数据 - python我正在使用python pandas处理一些数据。我已使用以下代码将数据导出到excel文件。writer = pd.ExcelWriter('Data.xlsx'); wrong_data.to_excel(writer,"Names which are wrong", index = False); writer.…
Python GPU资源利用 - python我有一个Python脚本在某些深度学习模型上运行推理。有什么办法可以找出GPU资源的利用率水平?例如,使用着色器,float16乘法器等。我似乎在网上找不到太多有关这些GPU资源的文档。谢谢! 参考方案 您可以尝试在像Renderdoc这样的GPU分析器中运行pyxthon应用程序。它将分析您的跑步情况。您将能够获得有关已使用资源,已用缓冲区,不同渲染状态上…