简体   繁体   中英

discord economy Bot by python and when i try to run my code it shows `AttributeError: module 'discord.ext.commands' has no attribute 'Bot'`

import discord
from discord.ext import commands
import json
import os
import random
[enter image description here][1]

os.chdir("C:\\Users\\ADVAITH\\Documents\\Economy Bot")

client = commands.Bot(command_prefix='e!')
 

@client.event
async def on_ready():
    print("Ready")

@client.command()
async def balance(ctx):
    await open_account(ctx.author)
    users = ctx.author
    users = await get_bank_data()
 
    wallet_amt = users[str(user.id)]["wallet"]
    users[str(users.id)]["bank"]

    em = discord.Embed(title = f"{ctx.author.name}'s balance",color = discord.Color.red)
    em.add_field(name = "Wallet balance",value = wallet_amt)
    em.add_field(name = "bank balance",value = bank_amt)
    await ctx.send(embed = em)


@client.command()
async def beg(ctx):
    await open_account(ctx.author)

    users = await get_bank_data()

    users = ctx.author

    earnings = random.randrange(101)




    await ctx.send(f"Someone gave you {earnings} coins!!")



    users[str(user.id)]["wallet"] += earnings 

    with open("mainbank.json","w") as f:
        json.dump(users,f)








    users[str(user.id)]["wallet"]

 
async def open_account(user):
    with open("mainbank.json","r") as f:
        users = json.load(f)

        if str(user.id) in users:
            return False
        else:
            users[str(user.id)] = {}
            users[str(user.id)]["wallet"] = 0
            users[str(user.id)]["bank"] = 0

        with open("mainbank.json","w") as f:
            json.dump(users,f)
        return True


async def get_bank_data():
    with open("mainbank.json","r") as f:
        users = json.load(f)


client.run("XXXXXXXXXXXXXXXXXXX")

it says that AttributeError: module 'discord.ext.commands' has no attribute 'Bot' but have imported the commands and it doesn't allow my bot to come online and it says the following error:-

Traceback (most recent call last):
  File "c:/Users/ADVAITH/Documents/Economy Bot/EconomyBot.py", line 2, in <module>
    from discord.ext import commands
  File "C:\Users\ADVAITH\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\__init__.py", 
line 13, in <module>
    from .bot import Bot, AutoShardedBot, when_mentioned, when_mentioned_or
  File "C:\Users\ADVAITH\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\bot.py", line 
38, in <module>
    from .core import GroupMixin, Command
  File "C:\Users\ADVAITH\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 10, in <module>
    client = commands.Bot(command_prefix = "e!")
AttributeError: module 'discord.ext.commands' has no attribute 'Bot'

我建议删除并重新安装您的不和谐模块。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM