通过discord.py将图像从特定文件夹推送到服务器

通过discord.py将图像从特定文件夹推送到服务器,discord,discord.py-rewrite,python-os,Discord,Discord.py Rewrite,Python Os,我的discord机器人有一些问题,我会尽力解释。 因此,我有一个机器人的文件夹,其中包含一个机器人本身,还有一个名为commands的文件夹,基本上它是存储我的齿轮的地方,在commands文件夹中有一个名为images的文件夹,我在其中保存了图像,供我的机器人随机拾取。问题是,我无法告诉bot从该特定文件夹拍摄图像,而只有在我将图像直接放入bot的文件夹(第一个文件夹)时,它才起作用。我尝试过很多东西,比如: @commands.command() async def randomi

我的discord机器人有一些问题,我会尽力解释。 因此,我有一个机器人的文件夹,其中包含一个机器人本身,还有一个名为
commands
的文件夹,基本上它是存储我的齿轮的地方,在
commands
文件夹中有一个名为
images
的文件夹,我在其中保存了图像,供我的机器人随机拾取。问题是,我无法告诉bot从该特定文件夹拍摄图像,而只有在我将图像直接放入bot的文件夹(第一个文件夹)时,它才起作用。我尝试过很多东西,比如:

@commands.command()
    async def randomimage(self, ctx):
       for list os.listdir(./commands/images/):
        list = (images here)
        await ctx.send('take this', file=discord.File(random.choice(list)))
但这也没用,我可以把/commands/images/(image)放到每个图像上,但是列表很大,我不想在那里写每个图像的路径

机器人:

整个司令部:

import discord
import os
import random
from discord.ext import commands

class randomimage(commands.Cog):

    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def randomimage(self, ctx):
       #waiting for suggestion on this line
        list = (image list)
        await ctx.send('take this', file=discord.File(random.choice(list)))

def setup(client):
    client.add_cog(randomimage(client))

我在这里有点不在行,所以任何帮助都将不胜感激

我已经弄明白了这一点。显然,这个答案就像换一个目录一样简单

我已经使用了
os.chdir('./commands/images')
,它很有效

编辑:显然我错了,这也没用 更新:显然os.chdir可以工作,但是我必须指定完整的路径,比如
/home/user/discordbot/commands/images
,所以是的,它可以工作

import discord
import os
import random
from discord.ext import commands

class randomimage(commands.Cog):

    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def randomimage(self, ctx):
       #waiting for suggestion on this line
        list = (image list)
        await ctx.send('take this', file=discord.File(random.choice(list)))

def setup(client):
    client.add_cog(randomimage(client))