My dicord bot doesn't respond to commands - python

from discord.ext import commands
import discord
bot = commands.Bot(command_prefix="/", intents=discord.Intents.default())
TOKEN = "TOKEN"
#bot.event
async def on_ready():
print(f'Bot connected as {bot.user}')
#bot.command()
async def dosomething(ctx):
await ctx.send("I did something")
bot.run(TOKEN)
Bot is active and everything but when I try out /dosomething command nothing happens.

Change The Prefix To Anything Else But Not "/"
And Try Intents.all()
As i Know , Using /commands Needs Other libraries
Like This : discord_slash

Related

Discord bot won't go online

I've just started learn python and my discord bot won't go online. it just said
" Process exit with exit code 0". And there's no error with the code.
here's my code. enter image description here
Add await client.process_commands(ctx) and #client.event don't need parentheses(). Use the code given below:
#client.event
async def on_message(ctx):
if ctx.author == client.user:
return
await client.process_commands(ctx)
Use this entire code if it still not working:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
#bot.event
async def on_ready():
print('We are logged in!')
#bot.event
async def on_message(message):
if message.author==bot.user:
return
await bot.process_commands(message)
#bot.command()
async def ping(message) :
await message.channel.send("Pong!!")
bot.run("TOKEN")
You should try this instead
import os
import discord
from discord.ext import commands
discord_token = "Your Token"
client = discord.Client()
bot = commands.Bot(command_prefix="s!")
#bot.event
async def on_ready():
print("running")
bot.run(discord_token)
#bot.command()
async def on_ready():
print("running")
bot.run(discord_token)
and the output should be running
You should try this instead
import os
import discord
from discord.ext import commands
discord_token = "Your Token"
client = discord.Client()
bot = commands.Bot(client_prefix="!")
#client.command()
async def on_ready():
print("running")
bot.run(discord_token)
The code you gave is wrong, this is correct:
import os
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="!") # you don't need an extra discord.client Bot is enough
token = os.getenv("TOKEN")
#you should not run the program here you should run it at last
#bot.event #no need for brackets
async def on_ready():
print("running")
#bot.event
async def on_message(ctx):
if ctx.author == client.user:
return
#bot.command(name="span",description="YOUR DESCRIPTION HERE") # it is command and not commands
async def span_(ctx,amount:int,*,message):
for i in range(amount):
await ctx.send(message)
bot.run(token) #you should run the bot now only and this will work perfectly!
You can find the the documentation for discord.py here.

Commands for discord bot not working (Python)

I am not sure why the commands don't work. Whenever I enter !hello into my discord server the bot doesnt respond.
import discord
from discord.ext import commands
import os
my_secret = os.environ['Token']
client = commands.Bot(command_prefix='!')
#client.command(pass_context=True)
async def hello(ctx):
await ctx.send("Hello")
client.run(my_secret)
This should Work
I just tested it and it worked fine
did you install Discord? and did you wrote your Token right?
Also you should put this Code in yours so you see when the Bot is ready
#client.event
async def on_ready():
print(" ")
print("Bot started! | Informations:")
print(f"- Name: {client.user.name}")
print(f"- Bot-ID: {client.user.id}")
print(f"- Server using {client.user.name}:",
len(client.guilds))

My python based discord bot is not responding to any commands entered, and the initial method is not printing anything

When I iniatiate my discord bot,the on_ready method does not work. The bot comes online,but none of the code in the method prints in the command line. Also,the info command fails to work. This is all code that worked previously with another bot that I wrote, so I'm unsure as to what is failing to work. The code is included below.
from discord.ext import commands
import discord
client = discord.Client()
TOKEN = "insert token here"
description = "Bot that does things"
bot = commands.Bot(command_prefix="$", description="testbot")
#bot.event
async def on_ready():
print("Logged in as")
print(bot.user.name)
print(bot.user.id)
print("-----------------")
print("Developed by")
print("me")
#bot.command()
async def info(ctx):
embed = discord.Embed(
title="Commands", description="Here are the commands:", color=0xFFFF00
)
embed.add_field(name="meme", value="gives you a meme", inline=True)
print("Cmd entered")
client.run(TOKEN)
This is likely because you have both client (a discord.Client instance) and bot (a discord.ext.commands.Bot instance) defined. If you remove client and change client.run() to bot.run(), the bot should work.
from discord.ext import commands
import discord
TOKEN = "insert token here"
description = "Bot that does things"
bot = commands.Bot(command_prefix="$", description="testbot")
#bot.event
async def on_ready():
...
#bot.command()
async def info(ctx):
...
bot.run(TOKEN)

Discord.py Priveleged Intents stopping on_message and commands from working

from discord.ext import commands
from discord.ext import tasks
import random
import typing
from discord import Status
from discord import Activity, ActivityType
from discord import Member
from discord.ext.commands import Bot
from asyncio import sleep
intents = discord.Intents()
intents.members = True
intents.presences = True
print(discord.__version__)
bot = commands.Bot(command_prefix='!', intents =intents)
...
...
#bot.event
async def on_ready():
print('hiii, We have logged in as {0.user}'.format(bot))
await bot.change_presence(activity=discord.Game(name="Exploring the archives"))
bot.loop.create_task(status())
#bot.event
async def on_message(message):
if message.author.id == BOT_ID:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello Dad!')
await bot.process_commands(message)
#bot.event
async def on_member_update(before,after):
if before.status != str(after) :
print("{}, #{} has gone {} .".format(after.name,after.id,after.status))
#bot.event
async def on_member_remove(member):
print(f'{member} has left a server.')
#bot.event
async def on_member_join(member):
print(f'{member} has joined a server.')
await member.send('Private message')
#bot.command(pass_context=True)
async def summon(ctx):
await ctx.send ("I have been summoned by the mighty {}, ".format(ctx.message.author.mention) + " bearer of {}. What is your command?".format(ctx.message.author.id))
Hello. I was trying to build a discord Bot and I was mostly successful except from the fact that I couldn't get on_member_join & on_member_update to work (they didn't even seem to register a user entering or leaving the server so I concluded that I lacked some permissions). After a lot of searching I found this in the discord.py documentation and after adding the intents bit at the beggining of my code the on_member_join, on_member_remove & on_member_update worked, but the on_message event and all the commands do not work (i added a print at the beginning of on_message and nothing happened).
After some debugging I found out that the code that stops the commands from responding seems to be ,intents = intents) . However when this is removed, the on_member_join, on_member_remove & on_member_update (understandably) do not trigger.
Any advice?
I'm guessing that using intents = discord.Intents() has all intents set to False.
You can either use intents.messages = True or intents.all().

my commands dont work in my discord server

im trying to make a bot for my discord server, but all my commands dont work.
im using windows and pycharm to test and use the bot. i tried many different types but nothing works. im using python 3.7
import discord
from discord.ext import commands
import asyncio
from discord.ext.commands import Bot
Client = discord.Client()
client = commands.Bot(command_prefix='.')
#client.event
async def on_ready():
print("bot is active")
#client.command()
async def ping(ctx):
await ctx.send('pong')
await print("pong")
it doesn't crash or give an error, it just doesn't do anything in the command
Try this:
import discord
from discord.ext import commands
TOKEN = YOUR_TOKEN_GOES_HERE
client = commands.Bot(command_prefix = '.')
#client.event
async def on_ready():
print("Powering up the bot")
#client.event
async def on_message(message):
print("A new message!")
await client.process_commands(message)
#client.command()
async def ping(ctx):
await ctx.channel.send("Pong!")

Categories