Cannot call user ID when slash command sent in pycord

Question:

I am trying to create an intuitive discord bot that uses pycord as its library to be able to allow people to communicate to my bot & my features will be using slash commands. When I am trying to grab the ID of the user who sent the slash command, it results in the userId not being printed. Here is my code:

TOKEN = env.token
#Temporary token.

import discord
from discord.ext import commands
bot = commands.Bot()
print("Logging all data.")
#Login
@bot.event
async def on_ready():
    print(f"{bot.user} is online.")

#Register for beta
@bot.slash_command(name="register",description="Register for beta features.  ")
async def register_beta(ctx): 
    await ctx.respond("Paragon has given you access to beta features.", ephemeral=True)
    print(ctx.author.id())
bot.run(TOKEN)

and when I try to launch the bot & run the slash command, it gives me this error:

Ignoring exception in command register:
Traceback (most recent call last):
  File "/home/runner/Work/venv/lib/python3.8/site-packages/discord/commands/core.py", line 110, in wrapped
    ret = await coro(arg)
  File "/home/runner/Work/venv/lib/python3.8/site-packages/discord/commands/core.py", line 774, in _invoke
    await self.callback(ctx, **kwargs)
  File "main.py", line 16, in register_beta
    print(ctx.author.id())
TypeError: 'int' object is not callable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/Work/venv/lib/python3.8/site-packages/discord/bot.py", line 768, in process_application_commands
    await ctx.command.invoke(ctx)
  File "/home/runner/Work/venv/lib/python3.8/site-packages/discord/commands/core.py", line 306, in invoke
    await injected(ctx)
  File "/home/runner/Work/venv/lib/python3.8/site-packages/discord/commands/core.py", line 116, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.commands.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: 'int' object is not callable

I am using pycord version 2.0.0b4. I couldn’t seemingly find any documentation for this issue.

Asked By: Ruler

||

Answers:

id is not a method. It is an attribute. Change print(ctx.author.id()) to print(ctx.author.id)

Answered By: Ryan
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.