如何从文件夹发送 image/gif? (discord.py)

How to send a image/gif from a folder? (discord.py)

我正在尝试将从网上抓取的 images/gifs 发送到不和谐频道,我 运行 遇到了一些问题,例如:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: PermissionError: [Errno 13] Permission denied: '__pycache__'

不完全确定问题的含义或解决方法!

代码:

模块

import discord
from discord.ext import commands
import random
# import giphy_client
# from giphy_client.rest import ApiException
from tokens import token
import random
import os

client = discord.Client()

client = commands.Bot(command_prefix="$", intents=discord.Intents.all())

@client.command()
@commands.has_role('test')
async def anime(ctx):

    #test = discord.Embed
    #test.set.title = ("hi"),
    #test.set.image = ('.png'),
    #test.set_footer(
    #    text=f"Powered by xxx")

    files = []
    for file in os.listdir():
            if file.endswith('.jpg'):
                files.append(file)

    await ctx.channel.send(file=discord.File(file))




client.run(token, bot=True)

我明白 bot=True 之类的东西是不需要的,那纯粹是因为我在测试东西。 我想从文件夹中将 images/gifs 作为嵌入发送,但我不完全确定该怎么做,因此我阻止了它,但无论哪种方式,我只是想弄清楚如何 import/send images/gifs 在不使用 api.

的情况下不和谐

您不能为 discord.File 函数传入列表。需要传入文件路径

files = []
for file in os.listdir():
    if file.endswith('.jpg'):
        files.append(file)

for file in files: # taking the path out of "files"
    await ctx.channel.send(file=discord.File(file))