I'm making a discord bot. when I send commands on the server from my account with the owner role, then everything is OK, it is executed.
photo_1
If I switch to another account that has the everyone role, then the bot stupidly does not react.
photo_2
here is a piece of code:
import discord
from discord.ext import commands
from dislash import InteractionClient, Option, OptionType
bot = commands.Bot(command_prefix='!')
inter_client = InteractionClient(bot)
#bot.event
async def on_ready():
print('Bot is launch!')
#inter_client.slash_command(description="Says Hello")
async def hello(ctx):
await ctx.respond(content='asfd', ephemeral=True)
bot.run(token)
Related
I'm making a bot for a discord server. He doesn't respond to messages, what should I do?
import discord
from discord.ext import commands
client = commands.Bot( command_prefix= "!")
#client.event
async def on_ready():
print('Bot active')
async def hello(ctx):
author = ctx.message.author
await ctx.send('Привет, как поживаешь')
#client.command()
async def send_a( ctx ):
await ctx.author.send("Привет")
token = "here my id"
client.run(token)
He must send messages to the chat, as well as private messages to the server participants
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 discord bot isn't replying to commands does anyone know why? i also get an error that says discord.gateway: Shard ID None has connected to Gateway
token = 'mytoken'
import discord
client = discord.Client(intents=discord.Intents.default())
#client.event
async def on_ready():
print('we are logged in as {0.user}'.format(client))
#client.event
async def on_message(message):
if message.author == client:
return
if message.content.startswith('$info'):
message.channel.send(f'> i am a bot currently being developed by agent')
client.run(token)
You should use a bot instead of a client, and don't forget to await async functions.
try this:
import discord
from discord.ext import commands
token = 'mytoken'
bot = commands.Bot(command_prefix='$')
#bot.event
async def on_ready():
print('Ready!')
#bot.command()
async def info(ctx):
await ctx.send('> i am a bot currently being developed by agent')
bot.run(token)
now try $info with the bot running.
Try to use discord.ext.commands instead of discord.client
token = 'mytoken'
import discord
from discord.ext import commands
client = commands.Bot(intents=discord.Intents.default())
#client.event
async def on_ready():
print('we are logged in as {0.user}'.format(client))
#client.event
async def on_message(message):
if message.author == client:
return
if message.content.startswith('$info'):
message.channel.send(f'> i am a bot currently being developed by agent')
bot.process_commands(message)
client.run(token)
I run the code and send "xd", selfbot replies "lmao", but if another user writes "xd", selfbot does not reply "lmao", What do I do to make it respond to any user or bot?
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
#TOKEN
TOKEN = "u token"
client = discord.Client()
b = Bot(command_prefix = "x")
#b.event
async def on_ready():
print("I ready")
#b.event
async def on_message(message):
if message.content == "xd":
await message.channel.send("lmao")
b.run(TOKEN, bot = False)
you cant do on_message for commands anymore so i recomand you do something like this
#b.command()
async def xd(ctx):
await ctx.send("lmao")
self botting is agaist discord TOS
I'm trying to make a selfbot using discord.py rewrite.
I'm encountering issues when attempting to create a simple command.
I'd like my selfbot to respond with "oof" when ">>>test" is sent.
Here is my code:
import asyncio
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix=(">>>"), self_bot=True)
#bot.event
async def on_ready():
print("Bot presence t u r n e d on ( ͡° ͜ʖ ͡°)")
#bot.command()
async def test(self, ctx):
await self.bot.say("oof")
bot.run("my token", bot=False)
A self-bot isn't a bot that uses self, it's a bot that logs in using your credentials instead of a bot account. Self bots are against the Discord TOS (and you're not doing anything that requires one), so you should set up a bot account through their website and use a bot account for your bot.
That said, bot.say has been replaced by ctx.send in rewrite, and you're not in a cog so you shouldn't use self as all.
from discord.ext import commands
bot = commands.Bot(">>>", self_bot=True)
#bot.event
async def on_ready():
print("Bot presence t u r n e d on ( ͡° ͜ʖ ͡°)")
#bot.command()
async def test(ctx):
await ctx.send("oof")
bot.run("my token", bot=False)