My goal is to make a discord bot that responds with the same message the user sent, and if the person sends a file, the bot sends the link of it.
I can get both parts working separately, but together I just run into issues (see bottom), in my current code only "stand-alone" file sending works, text messages not, and if you have text + a file, the file link will be sent by the bot but the text wont. If I put the 2nd part on top, then I get basically the complete opposite, only the text gets sent, no files.
My code:
@client.event # Clone message
async def on_message(message):
await client.process_commands(message)
if message.author == client.user:
return
ch = message.channel
await ch.send(message.content)
@client.event # Clone file
async def on_message(message):
await client.process_commands(message)
if message.author == client.user:
return
url = message.attachments[0].url
ch = message.channel
await ch.send(url)
Clone file on bottom always gives a IndexError: list index out of range
error
Clone message on bottom always gives a 400 Bad Request (error code: 50006): Cannot send an empty message
error