我的静音命令只得到我选择的原因的一个单词。有人知道为什么吗?
@client.command()
@commands.has_guild_permissions(kick_members=True)
async def tempmute(ctx, member: discord.Member, time, reason=None):
muted_role = discord.utils.get(ctx.guild.roles, name="Muted")
time_convert = {"s":1, "m":60, "h":3600,"d":86400, "w":604800, "mo":2592000, "y":31104000}
tempmute = int(time[:-1]) * time_convert[time[-1]]
await member.add_roles(muted_role)
embed=discord.Embed(title=f"Member Muted", description=f"{member} has been muted for {time}.")
embed.add_field(name=f"Moderator", value=f"{ctx.message.author}", inline=True)
embed.add_field(name=f"Reason", value=f"{reason}", inline=True)
await ctx.send(embed=embed)
await asyncio.sleep(tempmute)
await member.remove_roles(muted_role)
根据discord.py文档:
在定义为:
的简单命令中:@bot.command() async def echo(ctx, message: str): await ctx.send(message)
通过
?echo a b c
调用它将只获取第一个参数,而忽略其他参数。要解决这个问题,你应该通过?echo "a b c"
调用它,或者将签名更改为"消耗休息"行为。例子:@bot.command() async def echo(ctx, *, message: str): await ctx.send(message)
这将允许您使用
?echo a b c
而不需要引号。
在您的情况下,要么传递"quotes"
包围的原因,要么在命令签名中在time
和reason
之间添加*
参数。