【发布时间】:2022-11-20 04:18:29
【问题描述】:
每当您从该网站查看 YouTube 教程或代码时,都会发现真正的差异。一些开发人员使用client = discord.Client(intents=intents),而其他开发人员使用bot = commands.Bot(command_prefix="something", intents=intents)。现在我对其中的区别略有了解,但是当我使用它们中的任何一个时,我会从我的代码中的不同地方得到错误,这很令人困惑。特别是因为多年来 discord.py 发生了一些变化,所以很难找到真正的区别。
我试着坚持discord.Client 然后我发现commands.Bot 有更多的功能。然后发现使用commands.Bot时出错。
这方面的一个例子是:
当我尝试使用commands.Bot
client = commands.Bot(command_prefix=">",intents=intents)
async def load():
for filename in os.listdir("./Cogs"):
if filename.endswith(".py"):
client.load_extension(f"Cogs.{filename[:-3]}")
以上没有给出我的 Cogs 的任何回应,还说
RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited
client.load_extension(f"Cogs.{filename[:-3]}")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback`.
然后当我尝试使用discord.Client
client = discord.Client(command_prefix=">",intents=intents)
async def load():
for filename in os.listdir("./Cogs"):
if filename.endswith(".py"):
client.load_extension(f"Cogs.{filename[:-3]}")
上面也给我一个错误:Exception has occurred: AttributeError 'Client' object has no attribute 'load_extension'
从长远来看,哪个更好?确切的区别是什么?
【问题讨论】:
标签: python discord discord.py