-1

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.

TheVorkMan
  • 57
  • 4

2 Answers2

0

I used class instead of instance. So I need put ctx instead of disnake.Message - and this code must work.

TheVorkMan
  • 57
  • 4
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 17 '23 at 21:29
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}")
boez
  • 331
  • 1
  • 8