Hi so for a project i want to get the first word of message ( it will be an @ and after it I will remove a role but don't dwell on it )
I can't show my code because it will need a few dozen minutes of explaining some random things ( because it use other bots )
You can do this by splitting the message content with the .split()
method into a list, and then getting the first element of that list.
Message I send in the discord:
This is a test for stackoverflow
output in the console:
full message: This is a test for stackoverflow
first word: "This"
code:
@bot.event
async def on_message(message):
full_message = message.content
first_word_of_message = message.content.split()[0]
print(f'full message: {full_message}')
print(f'first word: "{first_word_of_message}"')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.