Skip to content
Advertisement

ctx.content in command and event difference (discord.py)

In discord.py is there some option how i can get access to msg.content (or ctx.content how everyone uses it) under a command ? Below you can see 2 examples of what i mean. The first one is event and i simply copy the message and let the bot to send it back. The second is command but there the msg.content doesnt work. My problem is that i dont want to use events so much and have everything under a command.

JavaScript

Someone types !rps hello. Outpup in discord is !rps hello

JavaScript

Someone types !rps hello (my prefix is !). Output is error in console:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: ‘Context’ object has no attribute ‘content’

Advertisement

Answer

In order to get the rest of the message of a command, you need to pass another argument. This argument will include all the messages that’s sent after !rps. Also, using ctx instead of msg is better in commands.

JavaScript

In this code, args argument includes all the messages after the !rps.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement