discord.pycommands.when_提及不适用于自定义前缀 [英] discord.py commands.when_mentioned not working with custom prefix

查看:23
本文介绍了discord.pycommands.when_提及不适用于自定义前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做什么:如果某人不知道前缀,他们可以提及该机器人并改用提及.经过研究,我发现了

试验3:

  command_prefix =命令.当提及和(get_prefix)时 

结果:没有错误,但漫游器不再响应提及,如下所示.

解决方案

when_提及_或应该传递给前缀列表,而不是获取该列表的函数.修改起来很容易:

  def when_提及_或_函数(func):def内部(机器人,消息):r = func(机器人,消息)r =命令.when_提及(机器人,味精)+ r返回r返回内部 

What I'm trying to do: If someone doesn't know the prefix, they can mention the bot and use the mention instead. After some research, I had found How to send commands to a bot by name? This made me want to try using the commands.when_mentioned or commands.when_mentioned_or functions alongside my custom prefix.

My problem: The bot either only responds to the mention (while throwing errors at me), or does not respond at all.

Here is the custom prefix code I am using: How to get a customizable prefix discord.py

Here is the client definition with the 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
    )

Below I have listed what I have tried. I am not sure what to try next, so I will be grateful for any help provided.

Trial 1:

command_prefix= commands.when_mentioned_or((get_prefix))

Result:

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

Trial 2:

command_prefix= commands.when_mentioned or (get_prefix)

Result: No error, but bot no longer responds to custom prefix as seen below.

Trial 3:

command_prefix= commands.when_mentioned and (get_prefix)

Result: No error, but bot no longer responds to mention as seen below.

解决方案

when_mentioned_or is supposed to be passed a list of prefixes, not a function for getting that list. It's easy enough to modify though:

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

这篇关于discord.pycommands.when_提及不适用于自定义前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆