简体   繁体   English

在 pycord 中发送斜线命令时无法调用用户 ID

[英]Cannot call user ID when slash command sent in pycord

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.我正在尝试创建一个直观的 discord 机器人,它使用 pycord 作为其库,以便能够允许人们与我的机器人进行通信,并且我的功能将使用斜杠命令。 When I am trying to grab the ID of the user who sent the slash command, it results in the userId not being printed.当我试图获取发送斜杠命令的用户的 ID 时,会导致 userId 不被打印。 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.我正在使用 pycord 版本 2.0.0b4。 I couldn't seemingly find any documentation for this issue.我似乎找不到有关此问题的任何文档。

id is not a method. id不是一种方法。 It is an attribute.它是一个属性。 Change print(ctx.author.id()) to print(ctx.author.id)print(ctx.author.id())更改为print(ctx.author.id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM