程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了AttributeError: 'Client' 对象没有属性 'command' 第 45 行大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决AttributeError: 'Client' 对象没有属性 'command' 第 45 行?

开发过程中遇到AttributeError: 'Client' 对象没有属性 'command' 第 45 行的问题如何解决?下面主要结合日常开发的经验,给出你关于AttributeError: 'Client' 对象没有属性 'command' 第 45 行的解决方法建议,希望对你解决AttributeError: 'Client' 对象没有属性 'command' 第 45 行有所启发或帮助;

我试图将 Reddit 合并到我的机器人中,但每次运行它时都会出现此错误。

"回溯(最近一次调用最后一次): 文件“main.py”,第 45 行,在 @clIEnt.command() AttributeError: 'ClIEnt' 对象没有属性 'command'"

我的代码:

import discord
from discord.ext import commands
import os
from datetiR_358_11845@e import datetiR_358_11845@e
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') 
datetiR_358_11845@e_NY = datetiR_358_11845@e.Now(tz_NY)
Times = (datetiR_358_11845@e_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',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 行)

非常感谢任何帮助:)

解决方法

所以您的问题是您混淆了 botclient 之间的差异。那些是不同的东西。
机器人更简单,它只是接收你的命令并处理它们。意味着它做了一些事情。如果你想在聊天中写作并做更多的事情,你需要一个客户。

除此之外,您不能创建这样的机器人: client = commands.bot(command_prefix=bot_prefiX) 正确的方法是:bot = Bot(command_prefix='$') 因为您已经导入了机器人。

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

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

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

大佬总结

以上是大佬教程为你收集整理的AttributeError: 'Client' 对象没有属性 'command' 第 45 行全部内容,希望文章能够帮你解决AttributeError: 'Client' 对象没有属性 'command' 第 45 行所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。