Discord.py Bot 将文件发送到 Discord 频道

Enz*_*ano 4 python bots discord discord.py

我试图让我的不和谐机器人向我的不和谐服务器发送一个 jpg 文件,但我不断收到一个错误,这似乎很不常见,因为我在互联网上找不到任何解决方案......

错误是... discord.ext.commands.errors.CommandInvokeError:命令引发异常:ClientRequestError:无法为https://discordapp.com/api/v6/channels/454374995758678029/messages编写请求正文

我的进口是

import time

import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
Run Code Online (Sandbox Code Playgroud)

我将提取的与错误相关的代码是

@bot.command(pass_context = True)

async def image(ctx):

        await bot.send_file(ctx.message.channel, open('halogen.jpg'))
Run Code Online (Sandbox Code Playgroud)

我只是缺少导入还是我的代码存在实际问题?

谢谢你们

小智 8

我正在研究同样的事情,我发现这有效:

    await ctx.send(file=discord.File(r'c:\location\of\the_file_to\send.png'))
Run Code Online (Sandbox Code Playgroud)

这是我找到它的地方:链接


Kow*_*eko 2

尝试这样做。

@bot.command(pass_context=True)
async def send(ctx):
    area=ctx.message.channel
    await bot.send_file(area, r"c:\location\of\the_file_to\send.png",filename="Hello",content="Message test")
Run Code Online (Sandbox Code Playgroud)

您可以在此处参考不和谐文档链接