Как мне сделать команду объявления в Discord.py? - PullRequest
0 голосов
/ 22 октября 2018

Независимо от того, как сильно я выгляжу, я не могу найти учебник о том, как сделать это в Discord.py, это все Discord.js.Вот мой текущий код:

@bot.command(brief='announce [message]')
    async def announce(ctx, message : str):
            print(str(message))
            if(str(ctx.message.author) == user):
                    await ctx.send('User Authentication Successful')
                    try:
                            for chan in channels:
                                    try:
                                            channel = bot.get_channel(chan)
                                            info = discord.Embed(title='New Announcement!', description=str(message), color=0xFFFFFF)
                                            await channel.send(embed=info)
                                    except Exception as e:
                                            await ctx.send(e)
                                            await ctx.send("Error: " + str(chan))
                    except Exception as e:
                            await ctx.send(e)

И это ошибка, которую я получаю.

Ignoring exception in command announce
Traceback (most recent call last):
  File "C:\Users\mashh\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\bot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "C:\Users\mashh\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 367, in invoke
    yield from self.prepare(ctx)
  File "C:\Users\mashh\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 345, in prepare
    yield from self._parse_arguments(ctx)
  File "C:\Users\mashh\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 304, in _parse_arguments
    transformed = yield from self.transform(ctx, param)
  File "C:\Users\mashh\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 212, in transform
    raise MissingRequiredArgument('{0.name} is a required argument that is missing.'.format(param))
discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.

Пожалуйста, помогите мне: (

РЕДАКТИРОВАТЬ: я извиняюсьесли что-то сбивает с толку. Я пытаюсь сделать команду -announce. Где я набираю -announce, и он объявляет (встроено) все, что было напечатано.

1 Ответ

0 голосов
/ 02 мая 2019

Вам необходимо добавить pass_context=True в @bot.command()

и изменить первую строку на: @bot.command(brief='announce [message]', pass_context=True)

, чтобы передать текст сообщения (класс данных сообщения) вфункция в качестве первого аргумента, ctx.

...