Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bot offline when i told it to be online #10041

Open
3 tasks done
SirPigari opened this issue Dec 12, 2024 · 4 comments
Open
3 tasks done

bot offline when i told it to be online #10041

SirPigari opened this issue Dec 12, 2024 · 4 comments
Labels
unconfirmed bug A bug report that needs triaging

Comments

@SirPigari
Copy link

SirPigari commented Dec 12, 2024

Summary

its hsould be online but its offline

Reproduction Steps

await bot.change_presence(status=discord.Status.online)

its still offline

Minimal Reproducible Code

await bot.change_presence(status=discord.Status.online)

await message.channel.send(f"Status: {bot.guilds[0].me.status} ({datetime.now().strftime('%H:%M:%S %d.%m.%Y')})")

# its still offline

Expected Results

to be online

Actual Results

is offline

Intents

intents = discord.Intents.default() intents.messages = True intents.guilds = True intents.members = True intents.message_content = True bot = commands.Bot(command_prefix="!", intents=intents) tree = bot.tree

System Information

  • Python v3.12.6-final
  • discord.py v2.5.0-alpha
    • discord.py metadata: v2.5.0a5129+g9806aeb8
  • aiohttp v3.10.11
  • system info: Windows 11 10.0.22621

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

discord shows that its online but the program says that its offline

@SirPigari SirPigari added the unconfirmed bug A bug report that needs triaging label Dec 12, 2024
@DA-344
Copy link
Contributor

DA-344 commented Dec 12, 2024

The code you have provided does not show how and where you start your bot, either by calling bot.run or a custom runner that calls bot.start, so we cannot know why it is not online.

@SirPigari
Copy link
Author

SirPigari commented Dec 12, 2024

The code you have provided does not show how and where you start your bot, either by calling bot.run or a custom runner that calls bot.start, so we cannot know why it is not online.

@bot.event
async def on_ready():
    global session_id
    session_id = bot.ws.session_id
    update_session()
    await tree.sync()
    print(f'Logged in as {bot.user}')
    await recreate_ticket_message()
    try:
        await update_presence()
        await bot.change_presence(status=discord.Status.online)
        await recreate_status_messages(bot)
        await status_message_ready()
        await status_message_update()
        await assign_member_role()
        await fetch_history()
        tasks.clear_task.start()
    except pypresence.exceptions.DiscordNotFound as e:
        print(e)
    except Exception as e:
        print(e)
    print("calling change_presence")
    await bot.change_presence(status=discord.Status.online)

if __name__ == "__main__":
    import variables
    bot_token = variables.DISCORD_BOT_TOKEN
    atexit.register(lambda: asyncio.run(on_shutdown()))
    try:
        bot.run(bot_token)
    except KeyboardInterrupt:
        asyncio.run(on_shutdown())

@pythonmcpi
Copy link
Contributor

please rtfm (quickstart, introduction, api reference)

@DA-344
Copy link
Contributor

DA-344 commented Dec 12, 2024

You should not do any API calls in on_ready, as you can get ratelimited, and therefore, disconnected. Also, changing your client status/presence that much can cause ratelimits, which, as said, can get you disconnected.
You should also know that on_ready can fire multiple times. If you need to do any setup for the bot, then override Client.setup_hook

And prevent the usage of atexit, if you need to do any asynchronous closure, then you can use a custom runner, there is an example of how to implement it on the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug A bug report that needs triaging
Projects
None yet
Development

No branches or pull requests

3 participants