英文:
Commands are no longer displayed since they are in the cog
问题
Here is the translation of the provided text:
我使用 discord.py
自从它们在这个模块中,我的命令不再显示。
代码开始
import discord
from discord.ext import commands
class Wuensche(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(name="goodnight", description="祝大家晚安")
async def goodnight(self, interaction: discord.interactions.Interaction):
embedVar = discord.Embed(title="晚安!",
description=f"{interaction.user.mention} 祝大家晚安。",
color=0x000000)
await interaction.response.send_message(embed=embedVar)
@commands.Cog.slash_command(name="goodmorning", description="祝大家早上好")
async def goodmorning(self, interaction: discord.interactions.Interaction):
embedVar = discord.Embed(title="早上好!",
description=f"{interaction.user.mention} 祝大家早上好。",
color=0xFFFF00)
await interaction.response.send_message(embed=embedVar)
@commands.Cog.slash_command(name="goodmidday", description="祝大家中午好")
async def goodmidday(self, interaction: discord.interactions.Interaction):
embedVar = discord.Embed(title="中午好",
description=f"{interaction.user.mention} 祝大家中午好。",
color=0x1a4646)
await interaction.response.send_message(embed=embedVar)
def setup(bot):
bot.add_Cog(Wuensche(bot))
for filename in os.listdir("cogs"):
if filename.endswith(".py"):
bot.load_extension(f"cogs.{filename[:-3]}")
print('[✅]已加载')
代码结束
这是运行注册中的一部分:
C:\Users\Yasha\PycharmProjects\BotFürFox\main.py:94: RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited
bot.load_extension(f"cogs.{filename[:-3]}")
RuntimeWarning: 启用 tracemalloc 以获取对象分配的跟踪信息
I've translated the code-related parts and removed the translation of non-code parts as per your request.
英文:
I use discord.py
My commands are no longer displayed since they are in the cog.
Code starts
import discord
from discord.ext import commands
class Wuensche(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(name="goodnight", description="Wünsche allen eine gute Nacht")
async def goodnight(self, interaction: discord.interactions.Interaction):
embedVar = discord.Embed(title="Gute Nacht!",
description=f"{interaction.user.mention} wünscht allen eine gute Nacht.",
color=0x000000)
await interaction.response.send_message(embed=embedVar)
@commands.Cog.slash_command(name="goodmorning", description="Wünsche allen einen schönen Morgen.")
async def goodmorning(self, interaction: discord.interactions.Interaction):
embedVar = discord.Embed(title="Guten Morgen!",
description=f"{interaction.user.mention} wünscht allen einen guten Morgen.",
color=0xFFFF00)
await interaction.response.send_message(embed=embedVar)
@commands.Cog.slash_command(name="goodmidday", description="Wünsche allen einen guten Mittag.")
async def goodmidday(self, interaction: discord.interactions.Interaction):
embedVar = discord.Embed(title="Guten Mittag",
description=f"{interaction.user.mention} wünscht allen einen guten Mttag.",
color=0x1a4646)
await interaction.response.send_message(embed=embedVar)
def setup(bot):
bot.add_Cog(Wuensche(bot))
for filename in os.listdir("cogs"):
if filename.endswith(".py"):
bot.load_extension(f"cogs.{filename[:-3]}")
print('[✅]Loaded')
Code ends
This is in the run register:
C:\Users\Yasha\PycharmProjects\BotFürFox\main.py:94: RuntimeWarning: coroutine 'BotBase.load_extension' was never awaited
bot.load_extension(f"cogs.{filename[:-3]}")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
答案1
得分: 1
自版本2.0.0起,setup
函数是异步的:
async def setup(bot):
await bot.add_cog(Wuensche(bot))
您还不需要在这个插件中再次加载扩展...
英文:
Since version 2.0.0 the setup
function is asynchronous:
async def setup(bot):
await bot.add_cog(Wuensche(bot))
You also don't need to load again the extensions in the cog...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论