【发布时间】:2021-12-01 07:55:15
【问题描述】:
问题
在discord.py 或discord-py-slash-command 中是否有类似斜线命令的事件侦听器,在发送斜线命令时执行代码?
我知道的
众所周知,discord.py中有事件监听器,比如on_message:
@bot.event
async def on_message(message: discord.Message):
await message.channel.send(f'You said {message.content}.')
discord.ext 有一个commands 的听众:
@bot.command()
async def hello(ctx):
await ctx.send('Hi!')
discord_slash 有斜杠命令:
@slash.slash(
name='hello',
description='Say hello.'
)
async def _hello(ctx):
await ctx.send('Hi!')
我需要什么
无论如何,每当使用斜杠命令时,我都想执行一些代码。我想它会像这样工作:
@slash.event()
async def on_slash(ctx):
# Something
在提到的库中是否有这样的功能,如果没有,我是否仍然可以在使用斜杠命令时以某种方式执行一些代码?
PS:第一个问题,所以我愿意接受改进建议。
【问题讨论】:
-
这很遗憾没有帮助,因为我不知道它是命令还是常规消息。
标签: python discord discord.py