I'm new to python (and programming in general), and I'm making a discord bot that will help me with my school schedule. So I want to type like !schedule to get my schedule for the day. I have a link to a "API" that my friend made which is "https://apischoolsoft.herokuapp.com/v1/schedule/TE19?today=true".
Here's the code:
lessons = str('https://apischoolsoft.herokuapp.com/v1/schedule/TE19?
today=true')
lessons = lessons.replace('och', '')
lessons = lessons.replace('}', '')
lessons = lessons.replace(']', '')
lessons = lessons.replace("'", '')
lessons = re.sub( '(?<!^)(?=[A-Z])', ' ', lessons )
lessons1 = lessons.split(",")
And so I was also given this code by someone else:
async def response2():
embed = discord.Embed(
title = 'Schema',
description = '',
colour = discord.Colour.blue()
)
embed.set_author(name='Schoolsoft')
embed.add_field(name='1', value=lessons1[1], inline=False)
embed.add_field(name='2', value=lessons1[2], inline=False)
embed.add_field(name='3', value=lessons1[3], inline=False)
embed.add_field(name='4', value=lessons1[4], inline=False)
embed.add_field(name='5', value=lessons1[5], inline=False)
return embed
But it says "Command raised an exception: IndexError: list index out of range", and I believe it's the value for lessons1 thats making it troublesome. I wrote the code below to call for this function:
@client.command(name='schema', help='This command returns schema')
async def schema(ctx):
# responses = schoolsoft_api.get_lessons(token, school, org_id)
#await ctx.send(r.text)
#embed.add_field(name="Field1", value="hi", inline=False)
embed = await response2()
await ctx.send(embed=embed)
I hope someone can help me with this since it would be really cool to get it work. What I basically want is that it will list everything from the link embedded instead of raw for a better look. Thanks in advance!
question from:
https://stackoverflow.com/questions/66052026/python-discord-bot-indexerror-list-index-out-of-range 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…