1

I am trying to run my bot currently and I keep running into the error “module 'discord' has no attribute 'bot'” and will not let me start my bot.

Here is my code:

import os
os.system("pip install py-cord")
import discord 
import time
import requests
import datetime
from discord.ext import commands
from discord.utils import get from discord.ext import tasks
from discord.ext.commands import Bot

bot = discord.Bot()

@bot.event
async def on_ready():
  print(f"WORKING AS {client.user}"

#  commands were removed due to it not letting me post the question but the code shouldn’t be a issue with the bot. It is slash commands. I will leave the beginning of the code below.

@bot.slash_command(description="Unlock the chat.")
@commands.has_permissions(manage_channels = True)
# code was here

bot.run(mytoken)

I’ve already tried changing it from bot to client with no luck. I also already tried the specific version being 2b1. I want to use slash commands with the bot and client says there is no attribute slash commands.I do not think it’s something to do with the lower portion of the code, it’s something to do with the top of the code if you can help, please and thank you.

choppa
  • 11
  • 2
  • 2
    What's your directory structure? Do you have any other files called `discord`? Any other `discord` python modules installed (`pip freeze list` will give you all the installed libraries)? Or, add a `print(discord)` after the imports and that should give us more information. – ESloman Jan 06 '23 at 10:50
  • Didn’t really work I’m using pebblehost to host it not my pc – choppa Jan 10 '23 at 06:31

1 Answers1

1

Your code looks perfectly fine.

However, this may be a library issue, and you're installing libraries in code (see below). If you accidentally installed discord.py, it may be causing this issue. In the console do the following:

pip uninstall discord.py

This will uninstall discord.py

Then install the proper pycord version:

pip install -U py-cord==2.4.0

Why you want to do this manually

The reason you want to do this manually is that installing libraries in code is not supported by PIP. See more here.

Blue Robin
  • 847
  • 2
  • 11
  • 31