Python Discord.py Rewrite Cog:TypeError:uu init_uuu()缺少1个必需的位置参数:';func';
我试图创建一个简单的命令,该命令在discord.py中用一个cog表示hi,但收到一个错误:Python Discord.py Rewrite Cog:TypeError:uu init_uuu()缺少1个必需的位置参数:';func';,python,discord.py-rewrite,Python,Discord.py Rewrite,我试图创建一个简单的命令,该命令在discord.py中用一个cog表示hi,但收到一个错误:TypeError:\uuuu init\uuuu()缺少一个必需的位置参数:“func”。我知道应该使用cogs来组织一组相关的命令。我只是在测试,以便创建一个更复杂的机器人。我查了一下房间,但没有发现任何有意义的东西。也许我错过了一件很明显的事情。请帮忙。我是初学者。 这是我的密码: class Test_Cog(commands.Cog): def __init__(self, bot):
TypeError:\uuuu init\uuuu()缺少一个必需的位置参数:“func”
。我知道应该使用cogs来组织一组相关的命令。我只是在测试,以便创建一个更复杂的机器人。我查了一下房间,但没有发现任何有意义的东西。也许我错过了一件很明显的事情。请帮忙。我是初学者。
这是我的密码:
class Test_Cog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Command()
async def sayhi(self, ctx):
await ctx.send('hi')
class Test_Application_Bot(commands.Bot):
async def on_ready(self):
print("Logged on as", self.user)
async def on_message(self, message):
# so that it doesn't respond to itself
if message.author == self.user:
return
print(message.content)
if message.content == "ping":
await message.channel.send("pong")
await self.process_commands(message)
def read_token():
with open("token.txt", "r") as f:
lines = f.readlines()
return lines[0].strip()
def main():
bot = Test_Application_Bot(command_prefix="!")
bot.add_cog(Test_Cog(bot))
bot.run(read_token())
if __name__ == "__main__":
main()
Decorator应该用小写字母书写 而不是
@commands.Command()
试试
@commands.command()
您能添加完整的错误跟踪吗?@commands.command()
应该是@commands.command()
@PatrickHaugh谢谢!它工作得很好@Anwarvic如果您想要完整的错误跟踪,它是回溯(最后一次调用):文件“discord\u bot.py”,第7行,类内Test\u Cog(commands.Cog):文件“discord\u bot.py”,第11行,Test\u Cog@commands.Command()TypeError:\uu init\uuu()缺少1个必需的位置参数:“func”