Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix error: module 'discord' has no attribute 'Bot'

The Situation:

I'm trying to make a simple discord bot with pycord, but every time I run the code it gives this error:

Traceback (most recent call last):
  File "main.py", line 3, in <module>
    bot = discord.Bot()
AttributeError: module 'discord' has no attribute 'Bot'

The code:

import discord

bot = discord.Bot()

@bot.slash_command()
async def test(ctx):
  await ctx.send('Success!')

bot.run('token')

What I have Done:

I've already checked if I have pycord installed and if my token is correct.

like image 472
BlazingLeaf12 Avatar asked Oct 18 '25 10:10

BlazingLeaf12


1 Answers

PyCord 2 beta 1 has just been released, so you can now install it with

pip install py-cord==2.0.0b1

rather than installing the version from source.

In order to get the example to work though, you need to add the applications.commands scope to your OAuth2 URL and re-register you bot with your test server.

Also, the quickstart guide now suggests adding a list of guild (server) id's when creating a slash_command :

The guild_ids attribute contains a list of guilds where this command will be active. If you omit it, the command will be globally available, and may take up to an hour to register.

like image 143
Mark Booth Avatar answered Oct 20 '25 01:10

Mark Booth