Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Break down this @client.command() snippet

I am trying to modify the following code but I’ve come to the conclusion I don’t fully understand what is taking place here.
If someone would be so kind as to break it down for me line by line I’d be appreciative.

@client.command(name='cmd')
async def cmd(context):
    command = context.message.content.replace("!cmd ", "")
    word_list = command.split()
    if word_list[0] == str(ID):
        word_list.pop(0)
        final_command = " ".join(word_list)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

command = context.message.content.replace("!cmd ", "")

Removes !cmd from the message by replacing it with an empty string

word_list = command.split()

Splits the message into a list, each word in the message as an item in the list

if word_list[0] == str(ID):
        word_list.pop(0)
        final_command = " ".join(word_list)

If the first word is an ID (str(ID) converts the ID to a string it so it can be compared) then remove it from the list. Then combine the words in the list back into a string, joined by spaces.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading