Как сделать команду tempmute discord.py?
Как сделать, так чтобы мьютить можно было не по секундам, а по минутам/часами/дни?
Вот код:
@bot.command(pass_context=True) @commands.has_permissions(administrator=True) async def mute(ctx, member: discord.Member, time=0, *, reason=None): emb = discord.Embed(title="", colour=discord.Color.blue()) await ctx.channel.purge(limit=1) author = ctx.message.author emb.set_author(name=f" был Замьютен!", icon_url=member.avatar_url) emb.set_footer(text=f"Дал мьют: \nПричина: \nСколько секунд: ", icon_url=ctx.author.avatar_url) await ctx.send(embed=emb) muted_role = discord.utils.get(ctx.message.guild.roles, name="Muted") await member.add_roles(muted_role) if time == None: await ctx.send("Время: Навегда") elif reason == None: await ctx.send("Причина: не указано") await asyncio.sleep(time) await member.remove_roles(muted_role) await ctx.channel.purge(limit=1) await ctx.send(f"Роль-мьют с снята\nПрошло: секунд")
- Вопрос задан более года назад
- 267 просмотров
1 комментарий
Простой 1 комментарий
Команда mute в discord.py. Создана роль с ограничением писать в чат, однако пользователь после получения мута может писать — в чем проблема?
Роль успешно выдается, в параметрах этой роли отключена возможность писать сообщения, однако пользователь (в моем случае второй аккаунт) все равно может писать. Что в таком случае делать? В чем ошибка в коде?
P.S. В коде нужные отступы есть, однако тут они не показываются.
- Вопрос задан более года назад
- 473 просмотра
2 комментария
Средний 2 комментария
discord.py How to add Mute command
I’m making a discord bot and I really want to make a mute command to mute toxic users. This is the code I’ve currently done, this isn’t the rewrite version.
@bot.command(pass_context = True) async def mute(ctx, user_id, userName: discord.User): if ctx.message.author.server_permissions.administrator: user = ctx.message.author role = discord.utils.get(user.server.roles, name="Muted") await client.add_roles(user, role) else: embed=discord.Embed(title="Permission Denied.", description="You don't have permission to use this command.", color=0xff00f6) await bot.say(embed=embed)
32.4k 12 12 gold badges 74 74 silver badges 85 85 bronze badges
asked Feb 12, 2018 at 19:00
107 1 1 gold badge 3 3 silver badges 11 11 bronze badges
What is your question?
Feb 12, 2018 at 19:06
I want to know how to make a mute command. Up above is my current code and it doesnt work and I dont know how to fix it.
Feb 12, 2018 at 19:06
«Why isn’t my code working» is considered off topic on Stack overflow.
Feb 12, 2018 at 19:08
and if you know how, how would I also add a time interval e.g >mute @toxicuser 60m
Feb 12, 2018 at 19:08
@chrisz No it’s not. @Leighton. Keep a dictionary or set of Users that have been muted, and the mute command just adds them to that list. Then in your on_message event you can call delete_message on their messages. See this similar question about muting channels
Feb 12, 2018 at 19:19
3 Answers 3
I rewritten my code and got a working peice of code, here it is if others need it 🙂
@bot.command(pass_context = True) async def mute(ctx, member: discord.Member): if ctx.message.author.server_permissions.administrator or ctx.message.author.id == '194151340090327041': role = discord.utils.get(member.server.roles, name='Muted') await bot.add_roles(member, role) embed=discord.Embed(title="User Muted!", description="**** was muted by ****!".format(member, ctx.message.author), color=0xff00f6) await bot.say(embed=embed) else: embed=discord.Embed(title="Permission Denied.", description="You don't have permission to use this command.", color=0xff00f6) await bot.say(embed=embed)
