discord.py commands.when_提到不使用自定义前缀时

2024-05-12 23:42:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做的事:如果有人不知道前缀,他们可以提到bot,并使用该前缀。经过一些研究,我发现How to send commands to a bot by name?这让我想尝试在自定义前缀旁边使用commands.when_mentionedcommands.when_mentioned_or函数

我的问题:机器人要么只响应提及的内容(向我抛出错误),要么根本不响应

下面是我正在使用的自定义前缀代码:How to get a customizable prefix discord.py

以下是带有command_prefix的客户机定义:

intents = discord.Intents.all()
client = commands.Bot(
    command_prefix= (get_prefix),
    description='A bot who wants your toes',
    owner_id=(394506589350002688),
    case_insensitive=True,
    intents=intents
    )

下面我列出了我尝试过的内容。我不确定下一步要尝试什么,因此我将感谢您提供的任何帮助。

试验1:

command_prefix= commands.when_mentioned_or((get_prefix))

结果:

TypeError: Iterable command_prefix or list returned from get_prefix must contain only strings, not function

试验2:

command_prefix= commands.when_mentioned or (get_prefix)

结果:没有错误,但bot不再响应自定义前缀,如下所示

Bot does not respond to bl!

试验3:

command_prefix= commands.when_mentioned and (get_prefix)

结果:没有错误,但bot不再响应如下所示的提及

Bot no longer responds to mention


Tags: ortosend内容getprefixbot错误
1条回答
网友
1楼 · 发布于 2024-05-12 23:42:28

when_mentioned_or应该传递前缀列表,而不是获取该列表的函数。不过,修改非常简单:

def when_mentioned_or_function(func):
    def inner(bot, message):
        r = func(bot, message)
        r = commands.when_mentioned(bot, msg) + r
        return r
    return inner

相关问题 更多 >