Bot error discord

**What should i do i am doing a discord music bot
its says

File “main.py”, line 9
for i in range(len(cogs)):
IndentationError: unexpected indent

:**

code snippet

Welcome to the community @lakatoffical
This means that there is an unexpected indent somewhere if you post all the code we may be able to help

import discord
from discrd.ext import commads

cogs = [music]

client = commands.Bot(command_preix==‘?’, intents == discord.Intents.all())
for i in range(len(cogs)):
cogs[i].setup(client)

client.run

(and where is the "for i in " there is the middle i is not blue)

1 Like

You want the code to be:

import discord
from discrd.ext import commads

cogs = [music]

client = commands.Bot(command_preix=='?', intents == discord.Intents.all())
for i in range(len(cogs)):
    cogs[i].setup(client)

client.run

ill check it i hope it will work

1 Like

it says

Traceback (most recent call last):
File “main.py”, line 2, in
from discord.ext import commads
ImportError: cannot import name ‘commads’ from ‘discord.ext’ (unknown location)

This is misspelt it should be from discord.ext import commands
So you code will look like:

import discord
from discord.ext import commands

cogs = ["music"]

client = commands.Bot(command_preix='?', intents=discord.Intents.all())
for i in range(len(cogs)):
    cogs[i].setup(client)

client.run

sorry i know iam dumb but now it says

Traceback (most recent call last):
File “main.py”, line 6, in
client = commands.Bot(command_preix=‘?’, intents=discord.Intents.all())
TypeError: BotBase.init() missing 1 required positional argument: ‘command_prefix’

Ok so I do not know how to fix this but I recermend making a discord bot simular to this one beacuse this one works:

import discord,os

intents = discord.Intents.all()
client = discord.Client(command_prefix='!', intents=intents)
 
@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))
 
@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith('!ping'):
        await message.channel.send('Pong!')
 
client.run(os.environ['BOT_TOKEN'])

And look at Discord Developer Portal for how to make it run

okey thanks for your help

Watch your spellings - Python will be picky about them. You’ve put “command_preix”, when it should be “command_prefix”. Coding Discord bots is not just about taking code that works and trusting that it works, it’s about understanding how it works so you’re able to expand on it and code bots again in the future.

Checking for typos should be your first step of debugging when you get an error like that, and it should be quite obvious that you’ve made a typo. I recommend tutorials on YouTube for making a bot using discord.py, but I’ve found the documentation to be useful in many cases recently.

1 Like

typo: from discrd.ext import commads it should be from discord.ext import commands

1 Like