这段代码有什么问题?(蟒蛇)属性错误:'Client'对象没有属性'command'



我是Python新手,我正在开发一个discord bot。但我每次都会运行这个错误。我不知道是什么问题,你能帮帮我吗?错误如下:第19行@client.command ()AttributeError: 'Client' object没有属性'command'

代码如下:

import discord
import random
from discord.ext import commands


class MyClient(discord.Client):
client = commands.Bot(command_prefix = '?')

# Start
async def on_ready(self):
print('Logged on as', self.user)
# Latency
client = discord.Client()
@client.command()
async def ping(ctx):
await ctx.send(f'Pong! {round(client.latency * 1000)}ms')

# 8ball
@client.command(aliases=['8ball'])
async def _8ball(ctx, *, question):
responses = ['Biztosan.',         
'Nagyon kétséges.']
await ctx.send(f'Kérdés: {question}nVálasz: {random.choice(responses)}')
# Clear
@client.command()
async def clear(ctx, amount=5):
await ctx.channel.purge(limit=amount)
await ctx.send(f'Kész!')
async def on_message(self, message):
word_list = ['fasz', 'kurva', 'anyad', 'anyád', 'f a s z', 'seggfej', 'buzi', 'f.a.s.z', 'fa sz', 'k U.rv@ any@dat']

if message.author == self.user:
return
messageContent = message.content
if len(messageContent) > 0:
for word in word_list:
if word in messageContent:
await message.delete()
await message.channel.send('Ne használd ezt a szót!')

messageattachments = message.attachments
if len(messageattachments) > 0:
for attachment in messageattachments:
if attachment.filename.endswith(".dll"):
await message.delete()
await message.channel.send("Ne küldj DLL fájlokat!")
elif attachment.filename.endswith('.exe'):
await message.delete()
await message.channel.send("Ne csak parancsikont küldj!")
else:
break
client = MyClient()
client.run(token)

我很确定这是由于你在哪里定义你的客户端变量,当我做我的不和谐机器人我是在javascript中做的所以我可能是错的,但我相信这是因为你试图调用一个尚未定义的变量,所以移动client = MyClient()行,这样它就定义了一旦你做了类

最新更新