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

User isn't gaining experience or going into the database #21

Closed
3 tasks done
InternalCosmos opened this issue Jan 26, 2023 · 2 comments
Closed
3 tasks done

User isn't gaining experience or going into the database #21

InternalCosmos opened this issue Jan 26, 2023 · 2 comments
Labels
user error The issue was not directly related to the library

Comments

@InternalCosmos
Copy link

Describe the bug
For some reason, award_xp isn't putting the user into the database or giving experience even if I use add_record to put them in.

To Reproduce
Minimal code to reproduce the bug/error
I have written the bare minimum to get a bot running with this code, as this is how I have my bot written.

import discord
import asyncio
from discordLevelingSystem import DiscordLevelingSystem
from discordLevelingSystem.errors import DatabaseFileNotFound, LeaderboardNotFound, ImproperLeaderboard, NotConnected,\
    ConnectionFailure, DiscordLevelingSystemError
from discord.ext import commands
from discord.ext.commands import AutoShardedBot
from pathlib import Path
from config import donator_role, prefixes, token

intents = discord.Intents.default()
intents.message_content = True
intents.members = True
intents.presences = True

if not Path(r'database/DiscordLevelingSystem.db').is_file():
    try:
        DiscordLevelingSystem.create_database_file(r'./database/')
    except (ConnectionFailure, DatabaseFileNotFound) as error:
        raise error


class DiscordBot(AutoShardedBot):

    def __init__(self):
        super().__init__(
            command_prefix=commands.when_mentioned_or(*prefixes),
            intents=intents
        )

    lvl = DiscordLevelingSystem(rate=1, per=60.0, awards=None, announce_level_up=True, stack_awards=True)

    async def on_message(self, message: discord.Message) -> None:
        if message.author == self.user or message.author.bot:
            return
        await self.process_commands(message)
        try:
            await self.lvl.add_record(
                guild_id=message.guild.id,
                member_id=message.author.id,
                member_name=message.author.name,
                level=0
            )
        except DiscordLevelingSystemError:
            raise DiscordLevelingSystemError
        try:
            await self.lvl.award_xp(
                amount=[15, 25],
                message=message,
                refresh_name=True,
                bonus=DiscordLevelingSystem(
                    donator_role,
                    20,
                    multiply=False
                )
            )
        except (DatabaseFileNotFound, LeaderboardNotFound, ImproperLeaderboard, NotConnected) as e:
            raise e


if __name__ == "__main__":
    try:
        DiscordBot.lvl.connect_to_database_file(r'database/DiscordLevelingSystem.db')
    except (ConnectionFailure, DatabaseFileNotFound) as error:
        raise error
    asyncio.run(DiscordBot().start(token=token))

Traceback if any

N/A

Required Checklist

  • I am using discord.py 2.0 or higher
  • I am using discordLevelingSystem 1.2.0 or higher
  • I have the required intents enabled

Version Info
What's the exact version of discordLevelingSystem/discord.py are you using?

  • discord.py: [2.1.0]
  • discordLevelingSystem: [1.2.0]
@Defxult
Copy link
Owner

Defxult commented Jan 28, 2023

Not sure why you're catching an error just to raise it...but the bonus parameter in award_xp is incorrect, please refer to the documentation. When you raise the DiscordLevelingSystemError, it is missing the message parameter.

Other than that, I tested your code and it works fine for me (I made the mentioned corrections above before I tested the code).

@InternalCosmos
Copy link
Author

Oh wow, I'm blind. Didn't even notice I was missing the .Bonus. Thanks for the help!

@Defxult Defxult added the user error The issue was not directly related to the library label Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user error The issue was not directly related to the library
Projects
None yet
Development

No branches or pull requests

2 participants