I want to print out and IndexError("List index out of range")
from my Discord bot into a channel if something is incorrectly executed. However my method, which I also used for AttributeErrors
, does not work. Where is the mistake I made?
try:
message = await channel.fetch_message(id_)
except IndexError:
return await ctx.send('The ID that was entered was incorrect, make sure you have entered the correct giveaway message ID.')
Messageable.fetch_message
never raises IndexError
, it raises the following:
discord.Notfound
- if the message was not founddiscord.Forbidden
- if you don't have the required permissionsdiscord.HTTPException
- when retrieving the message failedAnswering your question - you can simply except discord.NotFound
error
try:
message = await channel.fetch_message(message_id)
except discord.NotFound:
await ctx.send("The ID that was entered is incorrect, make sure you have entered the correct giveaway message ID.")