I need to check if user sends a .mp4 file with specified name (for example: pizza), and if that's true, bot send a message. Is there's a way i can do that?
CodePudding user response:
There's a better way to do this that isn't addressed in the dupe. The file object contains an attribute filename. You can then iterate over all the attachments and check for the file:
for file in <your message object goes here>.attachments:
if file.url == 'pizza.mp4':
# do stuff
CodePudding user response:
Try this in your on_message event:
@bot.event
async def on_message(message):
if message.guild is None and message.author != bot.user: # dm message
try:
file = message.attachments[0] # try getting the file
if "pizza" in str(file.url): # check if name is in the URL
await ctx.send("message") # send message
except: # user did not send a file/attachment
pass
