我正在努力使服务器版主能够暂时静音用户在他们的不和。我不是一个经验丰富的开发人员,在不和谐的机器人,但学习。
我想做什么?我正在努力让服务器所有者能够在他们不和谐的服务器中临时使用静音用户。
这就是我目前对Mute命令的看法:
@bot.command(pass_context=True)
async def mute(ctx, user: discord.Member):
if ctx.message.author.server_permissions.kick_members:
role = discord.utils.get(user.server.roles, name="Muted")
embed = discord.Embed(title="{} has been muted!".format(user.name), description="When the user needs unmuting do !unmute @user!" , color=0x0072ff)
embed.set_footer(text="Reversed by Damian#9209 | Reduction#9975")
embed.set_thumbnail(url=user.avatar_url)
await bot.add_roles(user, role)
await bot.say(embed=embed)
else:
embed = discord.Embed(title="Permission Denied.", description="You don't have permission to use this command.", color=0xff0000)
embed.set_footer(text="Reversed by Damian#9209 | Reduction#9975")
await bot.say(embed=embed)发布于 2020-01-01 22:21:24
我相信您一定知道,Discord.py库已更改为不再包含重写分支。这意味着静音命令对您来说变得更容易了。我会提供一些代码让你开始。我还将提供指向每一行的所有文档的链接。
@bot.command(name="tempmute",description="Temporarily mute a member")
@commands.has_permission(mute_members=True)
async def _tempmute(ctx,user:discord.Member):
muteRole = discord.utils.get(ctx.guild.roles,name="Muted")
await user.add_roles(muteRole)权限是对不和谐用户权限的检查。
utils.get是一个实用函数,可以逐步遍历可迭代性并找到正确的搜索筛选器。在这里,我们使用它找到一个名为“静音”的角色。
角色是一个协同函数(需要等待),它向用户添加一个或多个角色。
我还建议确保该角色禁用了speak权限,这样您就不必通过on_message事件来处理它。希望这能帮上忙!
https://stackoverflow.com/questions/50588179
复制相似问题