Discord bot not showing up in a server - python

I've created a bot and added to a server that I created for the purpose of bot testing as well as a server that I have admin permissions in. In the server I created, I can see that the bot is online and a member and can call the commands with no issue. However, I cannot see the bot in the other server and cannot call the commands.
I followed the same procedure for adding the bot to both servers by going thru the OAuth2 api.
I know that the bot connected to both servers because when I run:
#bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
print(bot.guilds)
I see both servers in the output.
Not really sure what the issue here is. If anyone can shed some light on potential causes of this issue. I'd greatly appreciate it. Thanks!
EDIT: I also see the bot in the 'Integrations' tab of 'Server Settings' for both servers.

Related

Discord.py Edit Channel when the Bot goes offline

Here my Code:
#bot.event
async def on_disconnect():
channel = bot.get_channel(1064939978569822309)
await channel.edit(name="Bot status: 🔴")
I dont have any errors but nothing happends if the bot disconnect.
Can anyone help me?
I reinstall the library.
According to discord.py's documentation. on_disconnect() is used for when the bot cannot connect to the discord server.
If the bot cannot connect to the server, it would not be able to get the discord channel (think about it, if you can't connect to discord you would not be able to send any message at all, much less editing the channel).
on_disconnect() is probably more for the usage on the local side of things (e.g. printing out logs to check why the bot cannot connect to the discord server) rather than to update the bot's status.
It is not possible to do this automatically, unless you have another bot monitoring this bot (which is not really viable as both bots could be down at the same time).
If you want to handle cases where you have to shutdown the bot (for maintenance purposes, as an example), you can instead have a function (an idea is you can have it as a discord command that can only be run by the bot's owner) to edit the channel before going offline.

Discord bot running locally but not on Azure

I have started working on a discord bot which works fine if I run it on my machine, but when I push it to Azure it claims the app is running yet the bot is offline
`
import discord
bot = discord.Bot()
#bot.command(name='whereami', help='print the current server name/id')
async def whereami(ctx):
await ctx.send(f'{ctx.author.name}, you are currently in {ctx.guild.name} ({ctx.guild.id}).')
#bot.event
async def on_ready():
print(f"We have logged in as {bot.user}")
#bot.slash_command(guild_ids=[guild ID])
async def hello(ctx):
await ctx.respond("Hello!")
bot.run("Token")
`
So far I've tried messing with the Azure settings, I made sure it was set to always on
Im assuming that you already installed all required libraries in azure, if it runs on your machine perfectly fine it most likely would be on azure’s end, i would recommend you try repelit ive hosted plenty of discord bots there no problem and very cheap, you can also go the vps route but those tend to be a bit more expensive. But if you want to stay with azure make sure all libraries and dependencies are there and check your settings. If it gives you error would help if you let us know what that error says.

Pycord message.content blank on guilds

I want to develop a discord bot. After trying the bot on my Raspberry Pi, I cannot read messages of the bot on the guilds. On the Raspberry Pi the program is working without any problems. Obviously I turned the pi off before starting the bot. I already tried kicking and reconnecting the bot on the servers, but that didn`t work. Private messages to the bot are running smoothly.
The messages are blank, so the event is called, but nothing is printed to the command line.
import discord
from discord.ext import commands
bot = commands.Bot()
#bot.event
async def on_message(message):
print(message.content)
bot.run("TOKEN")
The content of the message variable is (I have changed the ids and some other variables):
<Message id=953328581969116272 channel=<TextChannel id=956654537448771667 name='general' position=0 nsfw=False news=False category_id=953322537446663665> type=<MessageType.default: 0> author=<Member id=689200156665367842 name='my_name' discriminator='0000' bot=False nick=None guild=<Guild id=953322535556471664 name='Test' shard_id=0 chunked=False member_count=2>> flags=<MessageFlags value=0>>
I`ve found an open github problem, but because discord.py is not continued I have to ask it here. (The link: https://github.com/Rapptz/discord.py/issues/6820)
Switching back to API version 9 has solved the issue for me.
I've encountered the same issue and found the solution in the official Pycord Discord.
They have switched to the Discord API version 10 where message content has become a privileged intent in accordance with the new upcoming Discord changes (Message Content: Privileged Intent for Verified Bots).
In short, if your bot is in more than 75 servers you will need to verify it in order to access privileged intents.
Here's Pycord's detailed post for reference
Dated 20/03/2022
Hello #v2.0 Testers, Along with
https://github.com/Pycord-Development/pycord/pull/1012, pycord has
switched to API version 10. This version introduces a new privileged
intent: message content. Bots that use the master branch of pycord
need to turn this intent on in order to receive message contents and
invoke prefixed commands. However if you don't want to switch to v10,
you can change the API version back to 9
(https://github.com/Pycord-Development/pycord/pull/1032)
Turn the intent on:
bot = commands.Bot(..., intents=discord.Intents(message_content=True))
Switch back to API version 9:
discord.http.API_VERSION = 9
bot = commands.Bot(...)
See https://support-dev.discord.com/hc/en-us/articles/4404772028055
for more information about the intent.
This is the link to their Discord server. I would have not found the solution without being part of it.
https://discord.gg/sb5zZYnz
From October 25, 2021, accessing message content now requires enabling a new privilege intent.
Head to your developer portal and do this.
Applications ↦ Settings ↦ Bot ↦ Privileged Gateway Intents
Discord.py is back to development again, you should use it. You can ask these question in the discord.py Discord server and get quick response other than asking it at here!
Have fun coding!

Discord Bot always saying its online many times after being pinged by the flask server - PYTHON

Every time the flask server is pinged by UpTimeRobot, on Discord, my bot outputs it's online. I only want to say it one time, and not every time the server is pinged. How do I achieve this?
#client.event
async def on_ready():
print(f'You have logged in as {client}')
channel = discord.utils.get(client.get_all_channels(),name='general')
await client.get_channel(channel.id).send('Bot is now online!')
await client.get_channel(channel.id).send('Type $help to get more information.')
Click to see what the program is doing
This is not the full code
I think we need to see more information about your code. The on_ready event is only triggered when the client connects; therefore it would seem like you are recreating the client instead of reusing an instance of the client that already exists.
Also, which type of monitor are you using from UptimeRobot? Seems like it should not be triggering your Discord bot...

Discord Bot clear command doesn't execute after I added it to other server | Python

I'm clearly new to making bot on discord, might aswell python language. I just made a simple local bot which does have a clear command. At first it's working on my server but after when I added it to my friend's server it doesn't clear the amount of messages. I don't know if it's bug but I have the codes here, references just came from other youtubers.
#bot.command()
async def clear(ctx, amount=10):
await ctx.channel.purge(limit=amount)
the code is that simple but it doesn't execute in the server. Idk what happened to it.
Edit:
I just realised there are some errors that has happened while executing that command. The command was being ignored
Ignoring exception in command clear:
When, as an owner, you invite a bot to your server, you do it via a webpage. The webpage is displaying all the permissions that the bot asks and you can decide to grant it these permissions or not (by unchecking checkboxes).
Your friend might have unchecked some checkboxes when he invited your bot on its server, thus not granting it the permissions it needs to delete messages.

Categories