判断消息是否为GIF可以通过以下代码实现:
@client.event
async def on_message(message):
if message.attachments: # 检查消息是否包含附件
attachment = message.attachments[0]
if attachment.filename.endswith('.gif'): # 检查附件是否为GIF文件
# 如果是GIF文件,执行相应操作
await message.channel.send('这是一张GIF图:')
await message.channel.send(file=discord.File(attachment.url))
以上是基于Discord.py库的方法,我们可以在on_message事件处理程序中检查消息的附件。如果消息包含附件,我们可以检查附件的文件名是否以'.gif”结尾,如果是,则将其发送回通道。注意,我们需要使用discord.File(attachment.url)将附件发送回通道。