如何覆盖 HelpFormatter 中的 get_ending_note()?
how to override the get_ending_note() from HelpFormatter?
我需要帮助来覆盖来自 HelpFormatter
的 get_ending_note()
由于帮助命令默认为英文,而我的机器人应该在西班牙服务器中,我需要更改
"type !help command for help on a command..." 帮助消息末尾的一行为西班牙语。
我知道这不是 discordAPI/discord.py 特定的,而是 python,所以如果有人向我解释如何覆盖 python 上的 class 会很棒适用于这种特定情况,因为我发现谷歌搜索的教程让我更加困惑而不是帮助我理解
您需要创建 HelpFormatter
的子类并将该子类的实例传递给 Bot
:
from discord.ext.commands import Bot, HelpFormatter
class MyFormatter(HelpFormatter):
def get_ending_note(self):
return "This is the new ending note"
bot = Bot("!", formatter=MyFormatter())
我需要帮助来覆盖来自 HelpFormatter
的 get_ending_note()由于帮助命令默认为英文,而我的机器人应该在西班牙服务器中,我需要更改 "type !help command for help on a command..." 帮助消息末尾的一行为西班牙语。
我知道这不是 discordAPI/discord.py 特定的,而是 python,所以如果有人向我解释如何覆盖 python 上的 class 会很棒适用于这种特定情况,因为我发现谷歌搜索的教程让我更加困惑而不是帮助我理解
您需要创建 HelpFormatter
的子类并将该子类的实例传递给 Bot
:
from discord.ext.commands import Bot, HelpFormatter
class MyFormatter(HelpFormatter):
def get_ending_note(self):
return "This is the new ending note"
bot = Bot("!", formatter=MyFormatter())