I am am making a discord bot in python.
In the output it says that I have 4 errors.
I do not understand why.
I have installed discord.py and I am using Python 3.5.
Any ideas as to what is going on?
Errors:
E0611:No name 'exe' in module 'discord'
E0602:Undefined variable 'message'
E0401:Unable to import 'discord.exe.commands'
E0602:Undefined variable 'message'
Code:
import discord
from discord.exe.commands import Bot
from discord.ext import commands
import asyncio
import time
Client = discord.Client()
client = commands.Bot(command_prefix = ";")
#client.event
async def on_ready():
print("The bot is sailing on the seven seas")
#client.event
async def on_message(maker):
if message.content == "cookie":
await client.send_message(message.channel, ":cookie:")
client.run("1NDE2--CHANGED--L24CMo"))
First error: You imported discord.exe; its called discord.ext
Second error: You assigned the message argument to the name maker in the on_message declaration. Change it to on_message(message) to get the variable
Related
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:\Users\user\OneDrive\Desktop\coding\discord\server bots\test.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?
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")
The syntax is commands.Bot() with from discord.ext import commands before (which is your case).
Also don't forget to specify the intents.
I am trying to make a discord bot send the message like "hi guys" with discord.py whenever it joins a server. but the code that I am trying to use to send the message does not work. It doesn't show any errors however.
code: (some of the imports are for other stuff in the code)
import discord
import os
import random
import time
from discord import channel
from discord.message import DeletedReferencedMessage, Message
from discord.utils import find
client = discord.Client()
#client.event
async def on_member_join(member):
if member == client.user:
await channel.send('hi guys')
Please tell me what is wrong so that I can get it working. (I am fairly new to coding in python btw)
Change on_member_join to on_guild_join.
on_member_join: called when a member joins the guild
on_guild_join: called when the bot joins a guild
Guys I'm making a discord bot but i have an error it says "name 'bot' is not defined". Can anyone help?
Thanks
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions
client = commands.Bot(command_prefix = ';')
#client.event
async def on_ready():
print("{0.user} logged in as".format(client))
#bot.command(pass_context=True)
#has_permissions(administrator=True)
async def help(ctx):
await ctx.send('Help')
client.run('TOKEN')
You need to either use Client or Bot to instance your bot.
In your code you are instancing the bot as Client, but you are trying to create a command using #bot.command().
You need to use either #client.command() or #commands.command().
I'm trying to make a discord bot with discord.py for my discord server, I have extremely basic code that should get the bot online but instead just opens and then crashes.
import discord
#client.event
asnyc def on_ready():
print 'bot read`enter code here`y'
client.run('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
I do have the token normally I just didn't want to leak. I appreciate all the help.
I found a nice tutorial to create a discord bot in python. Therefore you can create a connection with the following code:
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
#client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
client.run(TOKEN)
And I would suggest to rename the file from 'discord' to 'bot' or something else, so there are no conflicts with the import.
Hello everyone i was making a bot using discord.py rewrite on pycharm but once there was a error on one of my cogs but the console didn't show any error and it didn't send any message so I had to search a lot about the error. I want to know why its like that.
My main code of the bot is:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix="your prefix")
client.load_extension("extension name")
#client.event
async def on_ready():
print("bot is ready")
client.run('your token
I'm not sure why it doesn't but google will sure help!
You forgot to end the string at client.run so here's the correct code.
import discord
from discord.ext import commands
client = commands.Bot(command_prefix="your prefix")
client.load_extension("extension name")
#client.event
async def on_ready():
print("bot is ready")
client.run('your token')