未定义Python机器人名称MyClient

时间:2020-06-04 23:12:09

标签: python discord

我用Python编程了一个不和谐的机器人,我做了第一步,但遇到了错误 NameError:名称“ MyClient”未定义

import discord
#Einloggen
class auth(discord.Client):
  async def on_ready(self):
    print("Bot is logged in!")

#Wenn Nachricht 
async def on_message(self, message):
  print("Message from  " + message.author + " contains " + message.content)

client = myclient()
client.run("My Token")

在我的文件中,我的令牌已粘贴 也许有人可以ha我,说我怎么了

2 个答案:

答案 0 :(得分:1)

您已经继承了discord.Client类,因此不需要client = myclient()

您的客户名称为auth,因此您必须使用auth.run()

您的事件监听器on_ready()on_message必须处于同一级别。

on_message()也没有self,只有message

这是完整的代码:

import discord

class auth(discord.Client):
    async def on_ready(self):
        print("Bot is logged in!")

    async def on_message(message):
        print("Message from  " + message.author + " contains " + message.content)

auth.run("My Token")

答案 1 :(得分:0)

您忘记了用File jarFile = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()); execPath = String.valueOf(jarFile.getParentFile()); 装饰功能。我们一直都在错过一个简单的错误;)。

@client.event
相关问题