I
I
Igor Gafarchik2020-05-23 15:04:39
Python
Igor Gafarchik, 2020-05-23 15:04:39

Discord.py bot role error?

Good day!
I wrote a discord bot in python and an error occurred when adding new functions.
The function should return roles, but for now it returns this:

Traceback (most recent call last):
  File "C:\Users\gafig.DESKTOP-B4N254S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\bot.py", line 892, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\gafig.DESKTOP-B4N254S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\core.py", line 790, in invoke
    await self.prepare(ctx)
  File "C:\Users\gafig.DESKTOP-B4N254S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\core.py", line 751, in prepare
    await self._parse_arguments(ctx)
  File "C:\Users\gafig.DESKTOP-B4N254S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\core.py", line 670, in _parse_arguments
    transformed = await self.transform(ctx, param)
  File "C:\Users\gafig.DESKTOP-B4N254S\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\core.py", line 516, in transform
    raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: member is a required argument that is missing.

Here is the function itself
@bot.command(pass_context=True)
async def вип(ctx,member:discord.Member):
    await ctx.channel.purge(limit = 1)
    vip_role = discord.utils.get(ctx.message.guild.roles,name = 'VIP')
    await member.add_roles(vip_role)
    retStr = (f"""```{member} получил VIP от администрации сервера!```""")
    embed=discord.Embed(title="Новый VIP",colour = discord.Colour.orange())
    embed.add_field(name="VIP",value=retStr)
    await ctx.send(embed=embed)

The funny thing is that the functions that were written before that work. Having considered this, I decided to copy the old function and change its name, but the error occurred. What caused the error and how to solve it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2020-06-16
@Gafarchik

MissingRequiredArgument means that the command did not receive the required argument.
The command written in your example requires you to specify a user.
Note: [p]- the prefix specified for your bot
[p]вип - will return an error
[p]вип DiscordTag#0000- will not return if a user with the DiscordTag#0000 tag exists on the server command is always Note: - I assume that this piece of code is used by you to delete the message with the command. If so, I recommend replacing it with to avoid the (possible) "racing condition"
pass_context=True
await ctx.channel.purge(limit = 1)await ctx.message.delete()

Note
Почему у меня создается ощущение, что где-то появился очень кривой русскоязычный туториал по ботам на discord.py?
Кривой - потому что с упоминанием pass_context и purge для удаления сообщений автора

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question