My discord bot is not responding to "test". There are no error messages, so I am very confused why this is happening.
I just started Python today and I wanted to learn how to make a Discord bot
import discord
client = discord.Client(intents = discord.Intents.default())
#client.event
async def on_ready():
general_channel = client.get_channel(1045161050024185899)
await general_channel.send('Bot Activated By-**GotYoHat** \nMade By **GotYoHat** using **Python**')
#client.event
async def on_message(message):
if message.content == 'test':
await message.channel.send('work')
client.run('the token is right here')
I searched the internet for an answer and I can't find a single answer online
You need to turn on intents.
Try to discord.Intents.all()
Related
I came back to creating bots on discord, but this time with Python, it seems I am doing something wrong, and I don't know what it is.
I placed a simple code, which is (command-reply), but the bot does not answer and does nothing about it.
My bot is online, I don't get errors in my terminal, and I am using the correct token.
Here is my code:
import discord
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
#client.event
async def on_message(message):
if message.content == "hello":
await message.channel.send("Hello there!")
client.run('BOT TOKEN')
You didn't enable the message_content intent.
Docs about intents: https://discordpy.readthedocs.io/en/stable/intents.html
import discord
from discord.ext import commands
from discord import Embed
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
#Prints bot is online to console
#bot.event
async def on_ready():
print("PythonBot is online")
#Replies Hey! if a user says Hello
#bot.event
async def on_message(message):
if message.content == 'Hello'.lower():
await message.channel.send("Hey!")
#Ping Command
#bot.command()
async def ping(ctx):
await ctx.send("Pong!")
bot.run("TOKEN_HERE")
I have made this simple program with discord.py that has an Event, the bot says Hey! when a user says Hello and a Command, that has the bot reply Pong! when a user uses the !ping command. My issue is that the bot does not respond when either of these actions happen and there are no errors raised in the terminal. I get confirmation from the API that my bot has connected to my application's token and I receive "PythonBot is online" in the terminal when I run my program but nothing else in my program seems to work.
Take a look at the discord.py FAQ:
You need to change your following 2 lines
#bot.event
async def on_message(message):
to
#bot.listen('on_message')
async def on_message(message):
and that should fix your issue
My bot suddenly stopped responding to commands. I believe it's on Discord's end as any time I attempt to invite the bot, permissions only say "This will allow the developer to: Create commands in your server." I have a second bot that I haven't touched since the week it was made and it is having no problems. Am I doing something wrong in the developer portal? It's a super basic bot that sends text at the moment.
import discord
import os
from keep_alive import keep_alive
client = discord.Client()
#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
message.content
if "p.h" in message.content:
await message.channel.send('Hello!')
keep_alive()
client.run(os.getenv('TOKEN'))
Go discord developer portal > select your app > navigate to "bot" in sidebar
Enable message content intent, to allow the bot read message sent from the user
Im using the discord.py library and using replit for the bot, but my code doesnt work.
my code:
import os
import discord
from discord.utils import get
client = discord.Client()
#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.content == ";":
member = message.author
role = get(member.guild.roles, name="Recruiter")
await member.add_roles(role)
client.run(os.getenv("TOKEN"))
First of all, you're using client object and it is not a bot.
This is the way to create a proper bot (not client):
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
You can't code reactions roles without reading the discord.py docs. It involves lots of stuff.
If you want to code it yourself, the only way is to learn and do.
I tried making a secret in repl.it to put my bot's token in so i can code my bot but it doesn't recognize the variable TOKEN even though i made a System environment variable. I tried researching to see if someone has the same problem but I couldn't find anyone.
The code I written is in the following:
import discord
import os
client= discord.Client()
#client.event
async def on_read():
print('We Have Logged In As {0.user'.format(client))
#client.event
async def on_message(message):
if message.author == client:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
client.run(os.getenv('TOKEN'))