本文介绍了Discord.py Bot将文件发送到Discord频道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使我的discord机器人将jpg文件发送到我的discord服务器,但是由于在互联网上找不到任何解决方案,我不断收到错误消息,这似乎并不常见...

I am trying to make my discord bot send a jpg file to my discord server, but I keep getting an error that seems pretty uncommon as I can not find any solutions to it on the internet...

错误是...discord.ext.commands.errors.CommandInvokeError:命令引发了异常:ClientRequestError:无法为 https://discordapp.com/api/v6/channels/454374995758678029/消息

the error is...discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientRequestError: Can not write request body for 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

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

The code that I will pull out that the error is related to is

@bot.command(pass_context = True)

async def image(ctx):

        await bot.send_file(ctx.message.channel, open('halogen.jpg'))

我只是错过了导入吗,还是我的代码存在实际问题?

Am I just missing an import or is there an actual problem with my code?

谢谢大家

推荐答案

尝试以这种方式进行操作.

Try doing it this way.

@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")

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

You can refer to the discord documentation for it here link

这篇关于Discord.py Bot将文件发送到Discord频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 10:32