我对Disnake有意见。
当我尝试获取消息作者像名称,鉴别器和其他像这样-我得到这个错误:
Ignoring exception in command user:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\ext\commands\core.py", line 173, in wrapped
ret = await coro(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "d:\Other\discord-bot\test\test-discord.py", line 13, in _user
await ctx.send(disnake.Message.author.name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'member_descriptor' object has no attribute 'name'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\ext\commands\bot_base.py", line 589, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\ext\commands\core.py", line 914, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\ext\commands\core.py", line 182, in wrapped
raise CommandInvokeError(exc) from exc
disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'member_descriptor' object has no attribute 'name'
我的代码:
import disnake
from disnake.ext import commands
intents = disnake.Intents.all()
bot = commands.Bot(command_prefix="t!", intents=intents, activity=disnake.Game(name="testing, testing..."))
@bot.event
async def on_ready():
print("bot started")
@bot.command(name="user")
async def _user(ctx):
await ctx.send(disnake.Message.author.name)
bot.run("my token lol")
我怀疑这是我的错,因为我是一个新手在Disnake。我想我错过了什么。
2条答案
按热度按时间6ie5vjzr1#
我使用了class而不是instance。所以我需要把ctx而不是disnake.Message -这段代码必须工作。
jckbn6z72#
获取作者姓名:
ctx.author.name
。对于鉴别器:ctx.author.discriminator
查看此链接。所以你的代码看起来像这样: