【问题标题】:How to get custom prefix with when mentioned提及时如何获取自定义前缀
【发布时间】:2021-12-01 18:16:11
【问题描述】:

我一直在研究 discord.py 机器人。我有一个自定义前缀命令,该命令将前缀作为 str 返回,但出现错误。代码:

def get_prefix(bot, message):
with open('prefixes.json', 'r') as f:
    prefixes = json.load(f)
return prefixes[str(message.guild.id)]

intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix = commands.when_mentioned_or(get_prefix), help_command=None, intents=intents)
bot.remove_command("help")

错误:

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

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

试试:

prefixes = get_prefix
commands.when_mentioned_or(*prefixes)

when_mentioned_or 想要一个元组。如果你想列出一个清单。你需要*

【讨论】:

    猜你喜欢
    • 2020-05-10
    • 1970-01-01
    • 2020-02-06
    • 2021-03-31
    • 2021-03-30
    • 1970-01-01
    • 2020-11-25
    • 2014-07-08
    • 2021-04-04
    相关资源
    最近更新 更多