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.
Related
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.
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.
I wanted to try my hand at making a discord bot however I'm running into an issue where my bot will not come online. I've tried 2 different codes I've found from internet tutorials but neither of them will make the bot appear online or do anything. I've seen someone ask a similar question on here using a similar code to what I have implemented and was currently working with and said that their issues were coming from a certificate error (Discord Bot not coming online) but I'm not sure how I would go about resolving it. For context I'm using Python 3.9 on PyCharm and my code looks like this (I have used an actual token but I've heard its not good to give that out) :
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='.')
#client.event
async def on_ready():
print('bot is ready')
client.run('TOKEN')
Please ask if you need any more information that what I've already provided.
edit1:pycharm says that the import 'import discord' is unused is that why im having issues?
edit2:I have tried using the following command to get the bot to do something but it is still not working-
#client.event
async def ping(ctx):
await ctx.send('pong!')
I'm trying to get my discord.py bot hosted for free, and I heard Heroku is a good option. My dyno is working perfectly, and it's switched on, but when I deploy, my bot does not go online. I have no errors, it says it's deployed, but my bot never goes online.
I have tried regenerating the bot token, and putting it in my Heroku app, but it still won't work.
import discord
from discord.ext import commands
from discord.ext.commands import bot
import asyncio
import requests
import os
description = '''EchoBot by EchoNoahGaming'''
bot = commands.Bot(command_prefix='-', description=description)
#bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
#bot.command()
async def announcement(ctx, *, args):
"""Announcement command!"""
embed=discord.Embed(title="Announcement", description=args, color=0x7700aa)
embed.set_footer(text="By EchoNoahGaming")
await ctx.send("#everyone", embed=embed)
client.run(str(os.environ.get('BOT_TOKEN')))
That is the bot code.
I expected the bot to come online, because there were no errors, but it didn't, and it stayed offline.
The Procfile code is
worker: python3 bot.py
The requirements.txt content is
discord
asyncio
If you need anything else, tell me. The GitHub link is https://github.com/EchoNoahGaming/echobot/blob/master/ but i'll post any files on here so it's easier.
From the discussion in the comments, OP and I figured out what went wrong:
There is a typo on the last line: client.run should be bot.run
The requirements.txt file should be changed to
discord.py
requests
This is because requests isn't part of the Python standard library whereas asyncio is part of the standard library.
Fixing the above seemed to have solve the issues.
An auxiliary code review would be to remove redundant lines, such as
from discord.ext.commands import bot
(which gets overwritten by bot = Bot(...) anyway).
The asyncio and requests modules weren't used in the code, but I'll give you the benefit of the doubt and assume you're planning on using them. If not, remove them from your code (and, if applicable, from requirements.txt). This saves time in building the bot.
So, I am trying in the latest version of Discord.Py and Python 3.6.4 to detect when a user joins, it will send a message to them welcoming them. My code is as follows:
#client.event
async def on_member_join(member):
await client.send_message(member,"Welcome!")
This code doesn't seem to work, I have looked up already on how others did it but the code is outdated, couldn't find anything on the API either on how I would do this. Any help is appreciated!
MAJOR EDIT: Okay, so the code works fine but I'm getting a 403 Permissions Error. The Bot was re-invited with FULL PERMISSIONS and in server has FULL PERMISSIONS. So I have no idea why this is happening. The bot can send messages anytime anywhere but not specifically under the on_memer_join(member) ... why?
discord.py is going through a bit of a metamorphosis at the moment. There's the "async" branch, with version number 0.16, and there's the "rewrite" branch, version number 1.0, that isn't quite finished but many have started using anyways. To find out which you're using, just try running
import discord
print(discord.__version__)
The code you posted looks good for the "async" branch, so I suspect you're on the "rewrite" branch. Try
#client.event
async def on_member_join(member):
await member.send("Welcome!")
The documentation for the rewrite branch is here
For the Rewritten version of Discord.py, You need to enable Intents
intents = discord.Intents.all()
client = Bot.commands(command_prefix = '', intents = intents)
async def on_member_join(member):
await member.send('Welcome!')
You must enable intents in your bot application as well.
Sorry this is a late comment.