如何检查视频文件是否已发送到不一致的服务器?
我尝试使用
@client.event
async def on_message(message): # Event handler for income messages
if message.author == client.user:
return None
response = 'https://cdn.discordapp.com/attachments/690944063888687114/724771151041265704/thats_my_meme_now.mp4'
if video in message.content:
await message.channel.send(
response)
但这给了我以下错误:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\seanb\Desktop\python projects\discord bot\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "C:/Users/seanb/Desktop/python projects/discord bot/discord bot.py", line 21, in on_message
if video in message.content:
NameError: name 'video' is not defined
答案 0 :(得分:0)
此代码循环遍历所有视频格式,并检查附件中是否有任何一种格式。
@client.event
async def on_message(message):
if message.author.bot:
return
for a in message.attachments:
for e in ['3g2','3gp','amv','asf','avi','drc','f4a','f4b','f4p','f4v','flv','gif','gifv','m2ts','m2v','m4p','m4v','mkv','mng','mov','mp2','mp4','mpe','mpeg','mpg','mpv','mts','mxf','nsv','ogg','ogv','qt','rm','rmvb','roq','svi','ts','vob','webm','wmv','yuv']:
if a.filename[-len(e)-1:]==f'.{e}':
await message.channel.send('https://cdn.discordapp.com/attachments/690944063888687114/724771151041265704/thats_my_meme_now.mp4')
return