Skip to content
Advertisement

Bare bones level system receiving errors [closed]

I’m having issues with a very bare bones level system with my discord bot, here’s the error and code:

import discord
from discord.ext import commands,tasks

@client.event
async def on_message(message, member):
    if message.author.bot == False:
        if xp >= 250:
            level =+ 1
            await ctx.send(f'{member.mention} Has leveled up')
            if level >= 12:
                await member.add_roles(discord.Object(id='800794726935822358'))
            elif level >= 22:
                await member.add_roles(discord.Object(id='800794900370292746'))
        else:
            xp =+ 1

The error:

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:UsersJeremyAppDataLocalProgramsPythonPython310libsite-packagesdiscordclient.py", line 343, in _run_event
    await coro(*args, **kwargs)
TypeError: on_message() missing 1 required positional argument: 'member'

Advertisement

Answer

What @larsks said in the comment. Only pass message as a parameter for on_message. To get the member, instead do:

member = message.author This sets the member variable to the author of the message.

@client.event
async def on_message(message):

    member = message.author

    if message.author.bot == False:
        if xp >= 250:
            level =+ 1
            await message.reply(f'{member.mention} Has leveled up')
            if level >= 12:
                await member.add_roles(discord.Object(id='800794726935822358'))
            elif level >= 22:
                await member.add_roles(discord.Object(id='800794900370292746'))
        else:
            xp =+ 1
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement