W
W
whgsf2782902021-02-18 19:09:50
Python
whgsf278290, 2021-02-18 19:09:50

How to fix spam bot error?

In short, I want to prank a friend and "spam" him a little, but for some reason PyCharm writes an error.
I know it's probably simple. I just take all the code from the internet :/

CODE:

import discord
from discord.ext import commands
client = discord.Client()
bot = commands.Bot(command_prefix='!')

@bot.command(pass_context=True)
async def spam(ctx, m):
    await ctx.message.delete() #удаляем сообщение пользователя, чтобы не спалился
    count = 0
    while count < int(m):
        await ctx.send('@here Crash!!! ||Это пранк.||') #отправка текста
        count += 1


bot.run('нету токена тут')


Basically, everything should work, but...
Error :(
C:\Users\Не важно как меня зовут!\PycharmProjects\pythonProject1\venv\Scripts\python.exe C:/Не важно как меня зовут!/PycharmProjects/pythonProject1/main.py
Ignoring exception in command spam:
Traceback (most recent call last):
  File "C:\Users\Не важно как меня зовут!\PycharmProjects\pythonProject1\venv\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Не важно как меня зовут!\PycharmProjects\pythonProject1\venv\lib\site-packages\discord\ext\commands\core.py", line 856, in invoke
    await self.prepare(ctx)
  File "C:\Users\Не важно как меня зовут!\PycharmProjects\pythonProject1\venv\lib\site-packages\discord\ext\commands\core.py", line 790, in prepare
    await self._parse_arguments(ctx)
  File "C:\Users\Не важно как меня зовут!\PycharmProjects\pythonProject1\venv\lib\site-packages\discord\ext\commands\core.py", line 697, in _parse_arguments
    transformed = await self.transform(ctx, param)
  File "C:\Users\Не важно как меня зовут!\PycharmProjects\pythonProject1\venv\lib\site-packages\discord\ext\commands\core.py", line 542, in transform
    raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: m is a required argument that is missing.


I translated into Russian, and there is something like a mandatory argument m, well, it seems to be there. I'm just a newbie.
How to fix? Tell me, please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Nevzorov, 2021-02-19
@fixator10

Exception raised when parsing a command and a parameter that is required is not encountered

https://discordpy.readthedocs.io/en/stable/ext/com...
You did not specify the required argument "m" when calling the command, for example, it [p]spamwill give this error, [p]spam 12it will not.
If you want to make this argument optional, give it a default value, or add the typing.Optional.
https://discordpy.readthedocs.io/en/stable/ext/com...
I also recommend using converters .
Thus:
@bot.command()
async def cmd(ctx, m: int = 5):
    ...

E
Evgeniy _, 2021-02-18
@GeneD88

Change async def spam(ctx, m) -> async def spam(ctx, *, m)
https://discordpy.readthedocs.io/en/rewrite/ext/co...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question