Why is not my discord code working? When i run the progam, it gives an error saying: TypeError: 'module' object is not callable
Question:
Here is my code:
import discord
from discord.ext import commands
bot = discord.bot(command_prefix="!", help_command=None)
@bot.event
async def on_ready():
print(f"Bot logged in as {bot.user}")
bot.run("TOKEN")
The error i am getting:
File "c:UsersuserOneDriveDesktopcodingdiscordserver botstest.py", line 6, in <module>
bot = discord.bot(command_prefix="!", help_command=None)
TypeError: 'module' object is not callable
I haven’t coded in a while and i just got back to coding. I tried a simple discord.py program but it didn’t seem to work. Is there any way i could fix this?
Answers:
The syntax is commands.Bot()
with from discord.ext import commands
before (which is your case).
Also don’t forget to specify the intents.
yeah, you need to specify intents
here is the code to it works
import discord
from discord.ext import commands
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="!", help_command=None, intents = intents)
@bot.event
async def on_ready():
print(f"Bot logged in as {bot.user}")
@bot.command()
async def hello(ctx):
await ctx.send(f"hi {ctx.author.mention}")
bot.run("token")
Here is my code:
import discord
from discord.ext import commands
bot = discord.bot(command_prefix="!", help_command=None)
@bot.event
async def on_ready():
print(f"Bot logged in as {bot.user}")
bot.run("TOKEN")
The error i am getting:
File "c:UsersuserOneDriveDesktopcodingdiscordserver botstest.py", line 6, in <module>
bot = discord.bot(command_prefix="!", help_command=None)
TypeError: 'module' object is not callable
I haven’t coded in a while and i just got back to coding. I tried a simple discord.py program but it didn’t seem to work. Is there any way i could fix this?
The syntax is commands.Bot()
with from discord.ext import commands
before (which is your case).
Also don’t forget to specify the intents.
yeah, you need to specify intents
here is the code to it works
import discord
from discord.ext import commands
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="!", help_command=None, intents = intents)
@bot.event
async def on_ready():
print(f"Bot logged in as {bot.user}")
@bot.command()
async def hello(ctx):
await ctx.send(f"hi {ctx.author.mention}")
bot.run("token")