首页 > 解决方案 > 你好,我做了临时命令,我有一个问题

问题描述

所有在我的代码工作中我只有一个问题,时间不会结束,当时间结束时不要取消静音播放器我有:

class DurationConverter(commands.Converter):
  async def convert(self, ctx, argument):
    amount = argument[:-1]
    unit = argument[-1]

    if amount.isdigit() and unit in ['s', 'm', 'h', 'd']:
      return (int(amount), unit)

    raise commands.BadArgument(message='Not a valid duration')

@client.command(name='mute')
@commands.has_permissions(manage_messages=True)
async def tempmute(ctx, member: commands.MemberConverter, duration: DurationConverter, reason):
  channel = client.get_channel(841075670233776149)


  multiplier = {'s': 1, 'm': 60, 'h': 3600}
  amount, unit = duration

  guild = ctx.guild
  mutedRole = discord.utils.get(guild.roles, name="Muted")



  if not mutedRole:
    mutedRole = await guild.create_role(name="Muted")

    for channel in guild.channels:
      await channel.set_permissions(mutedRole, speak=False, send_messages=False, read_message_history=True, read_messages=False)
  await member.add_roles(mutedRole, reason=reason)
  embed = discord.Embed(title=f'Wyciszony!', description=f"{member.mention} został wyciszony. ", colour=discord.Colour.light_gray())
  embed.add_field(name="Powód:", value=reason, inline=False)
  embed.add_field(name="Wyciszenie zostanie usunięte za:", value=f"{amount}{unit}", inline=False)
  await ctx.send(embed=embed)
  await asyncio.sleep(duration)
  await member.remove_roles(mutedRole)

有人能帮我吗?我尝试了很多,但仍然没有。我想我的数据库可能有问题。

标签: pythondiscordcommanddiscord.py

解决方案


你输入时间了吗?这会很有帮助

import time

推荐阅读