0

I have an on_message() event, but I want to turn in into a command, the problem is that when I change it, the wait_for() function doesn't work. Is there any equivalent of wait_for() in @client.command()?

My code:

@client.event
async def on_message(message):
    channel = message.author
    def check(m):
        return m.channel == message.channel and m.author != client.user

    if message.content.startswith("!order"):
        await channel.send("in game name")
        in_game_name = await client.wait_for('message', check=check)

        await channel.send("in game ID")
        in_game_ID = await client.wait_for('message', check=check)

    else:
        await client.process_commands(message)```
Łukasz Kwieciński
  • 14,992
  • 4
  • 21
  • 39
  • What do you mean by "doesn't work"? What does happen? `wait_for` doesn't have anything to do with commands, it should work here. – Patrick Haugh May 21 '20 at 18:42

1 Answers1

4

First things first, that video shows your bot's login token. This is meant to be a secret key known only to you, and I would recommend taking down that video and changing the key here immediately! People with access to that key can take control your bot.

In the video that you sent in reply to a comment from Patrick Haugh, you used the discord.ext.commands framework, so that is what I will be using here. The ctx parameter in your order command is a Context, and instead of calling send() on the channel like you do in your video, you should call it on the context like this: ctx.send('foo').

Also, on lines 18 and 21, you use

await client.wait_for('ctx', check=check)

As explained here, the events you can use as the first argument of Client.wait_for() are given in the event reference, just remove the on_ prefix. In your case, I think you want on_message, so it would look something like this:

@client.command()
async def order(self, ctx: commands.Context):
    def check(message: discord.Message):
        return message.channel == ctx.channel and message.author != ctx.me

    await ctx.send('foo')
    foo = await client.wait_for('message', check=check)

    await ctx.send('bar')
    bar = await client.wait_for('message', check=check)

In this case, foo and bar are instances of discord.Message, and you can get the content of those messages using foo.content and bar.content respectively.

Pat
  • 66
  • 4