如何使用Python不一致机器人发送附件 [英] How to send an attachment using Python Discord bot

查看:20
本文介绍了如何使用Python不一致机器人发送附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的bot在被调用时向频道发送一个文件(不一定是图像,可以是文本文件)。以下是我的代码片段:

@bot.command(pass_context=True)
async def send(ctx):
    area=ctx.message.channel
    await bot.send_file(area, r"c:locationof	he_file_tosend.png",content="Message test")
但是,它会给我一个错误: AttributeError: 'Bot' object has no attribute 'send_file' 按照另一个答案的建议,我尝试将send_file替换为send,但也不起作用。此处的正确语法应该是什么?

推荐答案

您必须使用File类:

@bot.command()
async def send(ctx):
    file = discord.File("myfilepath")
    await ctx.send(file=file, content="Message to be sent")

这篇关于如何使用Python不一致机器人发送附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆