python - 你好,我做了临时命令,我有一个问题
问题描述
所有在我的代码工作中我只有一个问题,时间不会结束,当时间结束时不要取消静音播放器我有:
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)
有人能帮我吗?我尝试了很多,但仍然没有。我想我的数据库可能有问题。
解决方案
你输入时间了吗?这会很有帮助
import time
推荐阅读
- python - 在 Python 中模拟自定义异常
- android - 如何更改自定义 CursorAdapter 以仅在列表视图中显示给定片段的特定行?
- kubernetes - 无法访问谷歌云上暴露的外部 IP 的 Kubernetes pod
- azure - 面向用户的 Azure AD 和 Azure B2C
- c# - 我无法在 for 循环内的文本框中创建新行
- javascript - 使用 React-Router-Dom 隐藏 URL 扩展
- google-analytics - 在 Google Analytics 中删除用户的事件数据而不删除用户
- python - 如何在“文件版本”中写入数据,而不是在 python 中写入单个文件?
- android - 为什么重新启动活动时 Glide 会抛出“IllegalArgumentException”?
- c++ - 如何修复 C++ 上的循环