'How to access certain parts of a Discord input

I am quite new to the discord library in python and have currently made a discord bot. I have an idea for a few commands that vary the users input.

e.g ~TEST 4 will output 4 but,

~TEST 2 will output 2

I want to know how to use the characters after the basic command "~TEST" to be its variable that I can use to fill in other criteria.



Solution 1:[1]

You can do this easily by using command handling and arguments within discord.py

import discord
from discord.ext import commands
bot = commands.Bot(command_prefix = "-")

@bot.command()
async def test(ctx, number):
    await ctx.send(number)

Will then return whatever you put after "-test", example "-test 2" will return "2" and so on. To have more parameters you can add more variables.

import discord 
from discord.ext import commands 
bot = commands.Bot(command_prefix = "-") 

@bot.command()
async def test(ctx, number, name): 
    await ctx.send("The number is" + str(number) + "The name is " + str(name))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 trynfulf