discord.py commands.when_mentioned 无法使用自定义前缀
discord.py commands.when_mentioned not working with custom prefix
我想做的事情:如果有人不知道前缀,他们可以提及机器人并使用提及。经过一些研究,我发现 这让我想尝试使用 commands.when_mentioned
或 commands.when_mentioned_or
函数以及我的自定义前缀。
我的问题:机器人要么只响应提及(同时向我抛出错误),要么根本不响应。
这是我使用的自定义前缀代码:
这是带有 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)
结果:没有错误,但机器人不再响应自定义前缀,如下所示。
试验 3:
command_prefix= commands.when_mentioned and (get_prefix)
结果:没有错误,但机器人不再响应提及,如下所示。
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
我想做的事情:如果有人不知道前缀,他们可以提及机器人并使用提及。经过一些研究,我发现 commands.when_mentioned
或 commands.when_mentioned_or
函数以及我的自定义前缀。
我的问题:机器人要么只响应提及(同时向我抛出错误),要么根本不响应。
这是我使用的自定义前缀代码:
这是带有 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)
结果:没有错误,但机器人不再响应自定义前缀,如下所示。
试验 3:
command_prefix= commands.when_mentioned and (get_prefix)
结果:没有错误,但机器人不再响应提及,如下所示。
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