【发布时间】:2019-02-12 08:41:58
【问题描述】:
我已经尝试和研究了很多次,但仍然找不到。我想做一个删除服务器中选定角色的命令。这是我想出的(目前不关心权限):
@bot.command(pass_context=True)
async def delrole(ctx, role: discord.Role):
await bot.delete_role(role)
await bot.say("The role {} has been deleted!".format(role.name))
如果您能提供帮助,那就太好了。我使用了角色:discord.Role 和 delete_role()。感谢您的阅读。如果您有解决方案,请随时发表评论。
注意:此帖子适用于旧版本的discord.py,将不再有效。如果您正在寻找 discord.py 的重写 (v1) 版本的等效解决方案,您可以使用以下代码:
@bot.command(pass_context=True)
async def delrole(ctx, *, role_name):
role = discord.utils.get(ctx.message.guild.roles, name=role_name)
if role:
try:
await role.delete()
await ctx.send("The role {} has been deleted!".format(role.name))
except discord.Forbidden:
await ctx.send("Missing Permissions to delete this role!")
else:
await ctx.send("The role doesn't exist!")
【问题讨论】:
标签: python python-3.5 discord.py