0

Await won't work in an if statement. Is there any work arounds. I looked for like an hour and nothing found about it.

Source Code:

https://pastebin.com/fCu1Txg9

Thank you for the help if I get any!

Error: Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\student\PycharmProjects\MyStuff\venv\lib\site-packages\discord\client.py", line 307, in _run_event yield from getattr(self, event)(*args, **kwargs) TypeError: on_message() missing 1 required positional argument: 'ctx'

Creativious
  • 34
  • 10
  • `on_message` is called with only one argument, `message`. What exactly is the error you're getting? – Patrick Haugh Nov 13 '18 at 02:09
  • I'm not getting any error its just that its not working. This is what pycharm says. `Unresolved Renference ctx` and `Class 'Message' does not define '__await__', so the 'await' operator cannot be used on its instances` – Creativious Nov 13 '18 at 03:24
  • @PatrickHaugh Sorry had to Notify you. – Creativious Nov 13 '18 at 03:30
  • Pycharm is noticing that `send_message` returns a `Message`, and thinks that you're trying to await that message, instead of awaiting the coroutine to get a `Message`. I would ignore it. Try running the code, you should get a more informative error. – Patrick Haugh Nov 13 '18 at 03:35
  • @PatrickHaugh Actually that didn't fix it. Await works but now it doesn't work and none of my bot commands work.Also I still get no errors – Creativious Nov 13 '18 at 03:39
  • @PatrickHaugh I have an error I can give now. I changed the post to have it. – Creativious Nov 13 '18 at 03:46
  • [You cannot use `bot.say` outside of commands](https://stackoverflow.com/a/47899343/6779307). An event, like `on_message`, is not the same as a command. – Patrick Haugh Nov 13 '18 at 03:51
  • @PatrickHaugh The thing is that if I switch it to `send_message` the await function won't work and the event is broken. Also ctx is an unresolved reference – Creativious Nov 13 '18 at 03:54
  • `say` uses `send_message` internally. Try `await client.send_message(message.channel, "...")`. I think whatever you're trying to do with `Object` is the actual problem. Also, remove `ctx` from your event entirely. – Patrick Haugh Nov 13 '18 at 03:57
  • @PatrickHaugh That didn't fix it since ctx isn't working now. I updated the source code. its in the pastebin – Creativious Nov 13 '18 at 04:04
  • `on_message` doesn't have a `ctx`. Instead of using `ctx.message`, just use the message you pass as an argument. That's the only information the event is triggered with. – Patrick Haugh Nov 13 '18 at 04:05
  • That fixed about everything except that it's only running the first thing on the list through the if statement. Also it won't run any command now @PatrickHaugh – Creativious Nov 13 '18 at 04:17
  • See: [Why does on_message stop commands from working?](https://stackoverflow.com/q/49331096/6779307). – Patrick Haugh Nov 13 '18 at 04:52
  • I have no idea, but my objective is to react when you put in a command that doesn't exist. Now I'm just trying to get the bot to say that command does not exist when the exception `CommandNotFound` is activated. @PatrickHaugh – Creativious Nov 13 '18 at 05:12
  • See: [How to respond to wrong user command in discord.py](https://stackoverflow.com/q/52121740/6779307) – Patrick Haugh Nov 13 '18 at 13:24

0 Answers0