英文:
Disnake - Error when try get message author name
问题
I have problem with Disnake.
When I try to get the message author's name, discriminator, and other similar information, I get this error:
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'
My code:
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")
I suspect this is my fault because I'm a beginner in Disnake. I expect that I just missed something.
英文:
I have problem with Disnake.
When I try get message author like name, discriminator and other like this - I get this error:
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'
My code:
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")
I suspect this is my fault, because im a noob in Disnake.
I expect that I just missed something.
答案1
得分: 0
我使用类而不是实例。所以我需要将 ctx 放在 disnake.Message 之前 - 这段代码必须能够运行。
英文:
I used class instead of instance. So I need put ctx instead of disnake.Message - and this code must work.
答案2
得分: 0
To get the author's name: ctx.author.name
.
And for the Discriminator: ctx.author.discriminator
See this Link.
So your code would look like this:
@bot.command(name="user")
async def _user(ctx):
await ctx.send(f"{ctx.author.name}")
英文:
To get the author's name: ctx.author.name
.
And for the Discriminator: ctx.author.discriminator
See this Link.
So your code would look like this:
@bot.command(name="user")
async def _user(ctx):
await ctx.send(f"{ctx.author.name}")
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论