dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
717 stars 163 forks source link

on_ready event not working. #68

Closed nshout closed 3 years ago

nshout commented 3 years ago

Basically on_ready doesn't function as it should. If you have something like, print(f"Logged into {bot.user}"). That would never be printed.

dolfies commented 3 years ago

Please provide your code. on_ready() works perfectly fine for me.

You can also try the development branch.

nshout commented 3 years ago
bot = commands.Bot(prefix)

@bot.event
async def on_ready():
    print("Logged in")
    print(f"Logged into {bot.user}")

try:
    print("Logging in...")
    bot.run(token)
except discord.errors.LoginFailure:
    print("Invalid Token")
dolfies commented 3 years ago

A. You never started the bot.
B. That's not how you pass the prefix.

nshout commented 3 years ago

Well I do have a variable for the prefix.

nshout commented 3 years ago
import json
import discord
from discord.ext import commands

with open('./config.json') as f:
    config = json.load(f)
token = config.get('token')
prefix = config.get('prefix')

bot = commands.Bot(prefix)

@bot.event
async def on_ready():
    print("Logged in")
    print(f"Logged into {bot.user}")

@bot.listen()
async def on_message(message):
    print(message.content)

@bot.command(name='test', usage="", description = "test")
async def test(ctx, user_id):
    await ctx.message.delete()
    user = await bot.fetch_user(user_id)
    print(f"Used {prefix}test")
    print(user.avatar_url)

try:
    print("Logging in...")
    bot.run(token)
except discord.errors.LoginFailure:
    print("Invalid Token")
dolfies commented 3 years ago

It's bot = commands.Bot(prefix=prefix).

Also, what discord.py-self version are you using?

nshout commented 3 years ago

The latest development branch.

nshout commented 3 years ago

Well actually, after reinstalling and testing with the development branch, it wasn't able to login into any tokens. Then using pip to install it (discord.py-self 1.8.1) got it back to log into tokens, but without the fetch_user function which I need as well.

dolfies commented 3 years ago

On the development version, on_ready may take longer to trigger because it "subscribes" (fetches the member sidebar) of all guilds with less than 12k members by default iirc. You can disable this by passing guild_subscription_options = GuildSubscriptionOptions.off() when initializing bot, and then only subscribe the guilds you need with await guild.subscribe().

caiocinel commented 3 years ago

I use this library in a project together with a friend, and he also had this problem, the solution was to install Python 3.9 from the Windows Store, with that, the problem was solved.

nshout commented 3 years ago

On the development version, on_ready may take longer to trigger because it "subscribes" (fetches the member sidebar) of all guilds with less than 12k members by default iirc. You can disable this by passing guild_subscription_options = GuildSubscriptionOptions.off() when initializing bot, and then only subscribe the guilds you need with await guild.subscribe().

Thanks a lot, I got it to work that way.

dolfies commented 3 years ago

I use this library in a project together with a friend, and he also had this problem, the solution was to install Python 3.9 from the Windows Store, with that, the problem was solved.

tf lol How did that help

caiocinel commented 3 years ago

The creature probably has some malware on the PC that damages the AppData folder

Em qua., 4 de ago. de 2021 às 13:56, dolfies @.***> escreveu:

I use this library in a project together with a friend, and he also had this problem, the solution was to install Python 3.9 from the Windows Store, with that, the problem was solved.

tf lol How did that help

— You are receiving this because you commented.