【发布时间】:2021-02-09 05:23:48
【问题描述】:
我想在我的不和谐机器人中进行时间转换。现在,要使用 tempmute 命令,我只需要以秒为单位设置时间,并且我想进行转换,例如1s = 1; 1h = 3600 等
回答,我发现了什么,并不能解决我的问题。
这是我的代码:
# tempmute
@client.command()
@commands.has_permissions(kick_members=True)
async def tempmute(ctx, member: discord.Member, time=0, reason=None):
if not member or time == 0 or time == str:
return
elif reason == None:
reason = 'no reason provided'
tempmuteembed = discord.Embed(colour=discord.Colour.from_rgb(0, 255, 0))
tempmuteembed.set_author(icon_url=member.avatar_url, name=f'{member} has been tempmuted!')
tempmuteembed.set_footer(text=f"{ctx.guild.name} • {datetime.strftime(datetime.now(), '%d.%m.%Y at %I:%M %p')}")
tempmuteembed.add_field(name=f'ID:', value=f'{member.id}', inline=False)
tempmuteembed.add_field(name='Reason:', value=f"{reason}")
tempmuteembed.add_field(name='Duration:', value=f"{time}")
tempmuteembed.add_field(name=f'By:', value=f'{ctx.author.name}#{ctx.author.discriminator}', inline=False)
await ctx.channel.purge(limit=1)
guild = ctx.guild
for role in guild.roles:
if role.name == 'Muted':
await member.add_roles(role)
await ctx.send(embed=tempmuteembed)
await asyncio.sleep(time)
await member.remove_roles(role)
return
【问题讨论】:
-
欢迎来到 SO。请澄清你的问题。您要转换为秒的具体是什么?
标签: python discord discord.py