Intents not defined

Question:

I used a code from a video to add slash commands to a discord bot through nextcord but I keep running into this issue where intents isn’t defined.

from nextcord import Interaction, SlashOption, ChannelType
from nextcord.abc import GuildChannel
from nextcord.ext import commands
import nextcord

client = nextcord.Client(intents=intents)
token = 'hidden'
bot = commands.Bot()

testingServerID = 1047152916869427271

@client.event
async def on_ready():
    print("Bot is up and ready!")

@client.slash_command(guild_ids=[testingServerID])
async def youtubeslashcommand(interaction : Interaction):
    await interaction.response.send_message("Hi Youtube")

@client.slash_command(channel_ids=[testingServerID])
async def repeat(interaction : Interaction, message:str):
    await interaction.response.send_message(f"you said'{message}'")

bot.run(token)


This is my code
When i excecute it all I get is:

  File "c:UsersUserDocumentsdiscordbotorthox.py", line 6, in <module>
    client = nextcord.Client(intents=intents)
                                     ^^^^^^^
NameError: name 'intents' is not defined
Asked By: Iaon

||

Answers:

You need to set permissions of your bot with the Intents object.

intents = nextcord.Intents(messages=True, guilds=True, ...)

When creating the Bot object, pass the intents object as an argument:

commands.Bot(..., intents=intents)
Answered By: louis boehm

You can write in the code so:

bot = commands.Bot(command_prefix="!", intents=nextcord.Intents.all())

Answered By: Laker
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.