我正在尝试编写一个自动下载图像然后将它们发送到不同频道的机器人,但我 运行 遇到错误

Im trying to write a bot that automaticly downloads images and then sends them into a diffrent channel, but im running into an Error

完整的错误代码是

忽略 on_message

中的异常
Traceback (most recent call last):

File "C:\...\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:\...\DiscordBot\cogs\Post_image.py", line 33, in on_message
await self.bot.send(self.bot.get_channel("images")
file=discord.File(f"images/{picture}"))
AttributeError: 'Bot' object has no attribute 'send'

我尝试移动通道变量,但这没有帮助,我没有在网上找到任何解决方案。

为了完成我的重写代码

@commands.Cog.listener()
async def on_message(self, message):
    if message.author == self.bot.user:
        return
    if message.author.bot:
        return
    image_types = ["png", "jpeg", "gif", "jpg"]
    # channel = self.bot.get_channel("images")
    for attachment in message.attachments:
        if any(attachment.filename.lower().endswith(image) for image in image_types):
            await attachment.save(f"./images/{attachment.filename}")
    for picture in os.listdir("images"):
        if picture.endswith(".png") or picture.endswith(".jpeg") or picture.endswith(".jpg"):
            await self.bot.send(self.bot.get_channel("images"), file=discord.File(f"images/{picture}"))
        os.remove(f"images/{picture}")

self.botsend 不在一起。我要做的是创建一个变量来定义您希望将图像发送到的通道,然后让机器人发送它。像这样..

channel = self.bot.get_channel(imagechannelidhere)

await channel.send(file=discord.File(f"images/{picture}"))

channel 将使机器人找到您希望将图像发送到的频道。 所以我们让机器人通过 await channel.send

将文件发送到频道

我所说的 imagechannelidhere 是您希望机器人将图像发送到的频道的频道 ID。您必须输入 ID,而不是姓名。不需要引号。