1

I am trying to code a discord bot but when I run the program it gives the error

Traceback (most recent call last): File "c:/Users/phara/Documents/GitHub/RayzeBot/bot.py", line 41, in intents = discord.Intents.default() AttributeError: module 'discord' has no attribute 'Intents'

import discord, asyncio, os, platform, sys
from discord.ext.commands import Bot
from discord.ext import commands
import time
import random
if not os.path.isfile("config.py"):
    sys.exit("'config.py' not found! Please add it and try again.")
else:
    import config

""" 
Setup bot intents (events restrictions)
For more information about intents, please go to the following websites:
https://discordpy.readthedocs.io/en/latest/intents.html
https://discordpy.readthedocs.io/en/latest/intents.html#privileged-intents


Default Intents:
intents.messages = True
intents.reactions = True
intents.guilds = True
intents.emojis = True
intents.bans = True
intents.guild_typing = False
intents.typing = False
intents.dm_messages = False
intents.dm_reactions = False
intents.dm_typing = False
intents.guild_messages = True
intents.guild_reactions = True
intents.integrations = True
intents.invites = True
intents.voice_states = False
intents.webhooks = False

Privileged Intents (Needs to be enabled on dev page):
intents.presences = True
intents.members = True
"""

intents = discord.Intents.default()

I have the latest version of the discord API installed and am running python 3.8 What is causing the error and how do I fix it?

Ucef
  • 63
  • 1
  • 1
  • 5
  • Have you enabled privileged intents as this answer suggests? https://stackoverflow.com/questions/64831017/how-do-i-get-the-discord-py-intents-to-work – AS11 Apr 03 '21 at 03:54
  • Does this answer your question? [How do I get the discord.py intents to work?](https://stackoverflow.com/questions/64831017/how-do-i-get-the-discord-py-intents-to-work) – Łukasz Kwieciński Apr 03 '21 at 12:30

3 Answers3

3

Seems like a discord version issue. Intents was introduced in discord.py 1.5.0

import discord
print(discord.__version__)

This should be less than 1.5 in your pc.

Updating discord

pip install --upgrade discord.py

Or if you want to install a specific version

pip install discord.py==1.5.0
Ceres
  • 2,498
  • 1
  • 10
  • 28
  • Thanks upgrading helped but vscode continues to use 1.3.2 although I have installed 1.6.0 (I checked in cmd). Is their a way to fix this issue? – Ucef Apr 03 '21 at 15:04
  • Just fixed the issue had to use python version 3.9 instead of 3.8. – Ucef Apr 03 '21 at 15:11
  • Use [this](https://code.visualstudio.com/docs/python/environments#:~:text=To%20do%20so%2C%20open%20the,Settings%2C%20with%20the%20appropriate%20interpreter.) To change python version in vscode – Ceres Apr 03 '21 at 16:16
0

I just ran your code and it works on my pc. I'm using Python 3.6 but I don't think that should be an issue. Maybe try reinstalling discord API?

Bob lin
  • 45
  • 5
0

There are two cases here.

  1. The most obvious problem is that discord does not contain "intents" it contains "Intents". So all you need to do is change the i to a capital I.
  2. The second possible problem could be an older version of Intent release. To confirm your version do as the other answer mentioned in a new file and run that file.
  • [Welcome to StackOverflow.](/tour) Please see [answer]. `discord.py` does contain `Intents`. The OP's code has `Intents` and not `intents`. If you are referring to the variable `intents`: Python variables can be named in any way, regardless of the commonly used discord.py variable names. Even then, I don't think people use `Intents = ` over `intents = `. Learn the basics of Python before answering a Python question. Please re-read your answer before posting. If the question is already answered, avoid adding another answer with the same content. – The Amateur Coder Feb 21 '23 at 17:51