像用户一样调用命令



我有一个命令,我想调用它,就好像用户在不和谐中输入了命令一样,但我不知道如何实现它。

我想以用户身份调用它以使用after_invoke装饰器,因为这样做await self.first(msg)不允许我使用@first.after_invoke装饰器。有没有办法做到这一点?


class Bots(commands.Cog):
def __init__(self,client):
self.bot=client

@command()
async def first(self,msg):
await msg.send("OK")
@first.after_invoke
async def first_after(self,msg):
return None

@command()
async def second(self,msg):
await self.first(msg)

def setup(bot):
bot.add_cog(Bots(bot))

这是我的sudo命令,可能会派上用场。但是,您应该真正进一步解释您的问题,并为您所尝试的内容提供一些示例,因为我在这里不完全理解您的问题。希望这有帮助!

@checks.is_owner()
@commands.command(hidden=True, description="Force a user to run a command")
async def sudo(self, ctx, user: discord.Member, *, command):
message = ctx.message
prefix = await self.bot.get_prefix(message)
message.author = user
message.content = prefix + command
await self.bot.invoke(await self.bot.get_context(message))

最新更新