Python 属性错误:';客户';对象没有属性';命令';第45行

Python 属性错误:';客户';对象没有属性';命令';第45行,python,discord,Python,Discord,我试图将Reddit合并到我的机器人中,但每次我运行它时,它总是给我这个错误 “回溯(最近一次呼叫最后一次): 文件“main.py”,第45行,在 @client.command() AttributeError:“客户端”对象没有“命令”属性 我的代码: import discord from discord.ext import commands import os from datetime import datetime import pytz import random import

我试图将Reddit合并到我的机器人中,但每次我运行它时,它总是给我这个错误

“回溯(最近一次呼叫最后一次): 文件“main.py”,第45行,在 @client.command() AttributeError:“客户端”对象没有“命令”属性

我的代码:

import discord
from discord.ext import commands
import os
from datetime import datetime
import pytz
import random
import json
import requests
from replit import db
from keep_alive import keep_alive
import praw 
from discord.ext.commands import Bot

reddit = praw.Reddit(client_id="",
client_secret="",
username="",
password="",
user_agent="")

tz_NY = pytz.timezone('America/New_York') 
datetime_NY = datetime.now(tz_NY)
Times = (datetime_NY.strftime("%A, %B %d, %Y"))

c = ('Monday, Febuary 1: **B - Day** \nTuesday, Febuary 2: **A - Day**\nWednesday, Febuary 3: **B - Day**\nThursday, Febuary 4: **A - Day**\nFriday, Febuary 5: **B - Day**') 

e = ('Monday, Febuary 8: **A - Day** \nTuesday, Febuary 9: **B - Day**\nWednesday, Febuary 10: **A - Day**\nThursday, Febuary 11: **B - Day**\nFriday, Febuary 12: **A - Day**') 

foo = ['Jacob', 'Ashkan', 'Zeek', 'Omar', 'Ethan', 'Llani', 'Gabe']
doo = ['1',  '2', '3', '4', '5', '6', '7', '8', '9', '10']

client = discord.Client()
bot_prefix = "$"
client = commands.Bot(command_prefix=bot_prefix)

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.command()
async def meme(ctx):
    subreddit = reddit.subreddit("memes")
    all_subs = []

    top = subreddit.top(Limit = 5)

    for submission in top:
      all_subs.append(submission)

    random_sub = random.choice(all_subs)

    name = random_sub.title
    url = random_sub.title

    em = discord.Embed(title = name)

    em.set_image(url = url)

    await ctx.send(embed = em)

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$date'):
        embedVar = discord.Embed(title= Times, description="------", color=0x00ff00)
        embedVar.add_field(name="This Week", value= c, inline=False)
        embedVar.add_field(name="Next Week", value= e, inline=False)
        await message.channel.send(embed=embedVar)

    if message.content.startswith('$sus'):
        embedVar = discord.Embed(title= 'the sus test', description="------", color=0xFF0000)
        embedVar.add_field(name="Participant", value= random.choice(foo), inline=False)
        embedVar.add_field(name="Sus Meter", value= random.choice(doo), inline=False)
        await message.channel.send(embed=embedVar)

keep_alive()  
client.bot('TOKEN')
client.run(os.getenv('TOKEN'))
我试图修复客户端,但这里的问题是@client.commands()。(第45行)


非常感谢您的帮助:)

所以您的问题是您混淆了
bot
client
之间的区别。这些是不同的东西。
机器人更简单,它只接收来自您的命令并处理它们。意思是它做了些什么。如果你想在聊天中写作,做更多的事情,你需要一个客户

此外,您不能创建这样的机器人:
client=commands.Bot(command\u prefix=Bot\u prefix)
正确的方法是:
bot=bot(命令前缀=“$”)
,因为您已经导入了bot

您的方法是坚持使用客户端,而不是使用命令:

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content == 'someString':
        # do somethng

是什么让您认为您的
客户机
对象确实有一个
命令
方法?请提供预期的价格。显示中间结果与预期结果的偏差。我们应该能够将单个代码块粘贴到文件中,运行它,并重现您的问题。这还允许我们在您的上下文中测试任何建议。我们还希望您能够在错误点之前跟踪有问题的值。你对他们是如何获得这些价值观感到困惑吗?您和Python运行时系统似乎在异常点的
client
上存在分歧。您需要检查
客户端的类型和值。我还编辑了代码,错误出现在最后三行。再次感谢您的帮助。