如何检查视频文件是否已通过discord.py发送到服务器?

时间:2020-06-24 14:27:22

标签: python discord discord.py discord.py-rewrite

如何检查视频文件是否已发送到不一致的服务器?

我尝试使用

@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

1 个答案:

答案 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