简体   繁体   中英

How do I get user input from discord chat in python?

I am new to python and using the discord api. I am making a bot where I collect league of legends data and I already created the function where I can collect the data like Summoners Information and Ranked details. I am just having hard time figuring it out and I have been looking every where that could help me.

async def on_message(message):
    if message.author == client.user:
        return
    
    if message.content.startswith('!stats'):
        await message.channel.send(requestSummonerData("Munns"))
        await message.channel.send("-----------------------------------")
        await message.channel.send(requestRankData("Munns"))

This is my current code at the moment, so far I am just hard coding the name and the information printing part is working perfectly but I would like to do something like.stats xyz and it would print information for that person, Honestly. any advice would help me because cause in the end I am just trying to learn python and discords api. Thank you so much!

client = commands.Bot(command_prefix="!")

@client.command() 
async def stats(ctx, user):
    await ctx.send("put your msges here")

here's a slightly better way to do it and should get the job done now you just need to do !stats and it will send the message you send

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM