You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用discord.py斜杠命令发送文件失败问题求助

discord.py斜杠命令发送文件失败的解决方法

错误根源

你的代码里重复对文件对象进行了discord.File包装:先创建了file_to_send = discord.File("LoveCherryMotion.mp4"),调用send_message时又把这个已包装好的对象再传给discord.File(),这会触发参数类型错误,导致机器人无法正常处理文件发送请求。

修正后的代码

直接使用已创建的文件对象即可:

@bot.tree.command(name="lcm", description="Love Cherry Motion") 
async def lcm(interaction: discord.Interaction): 
    file_to_send = discord.File("LoveCherryMotion.mp4") 
    await interaction.response.send_message(file=file_to_send)

也可以简化成一步:

@bot.tree.command(name="lcm", description="Love Cherry Motion") 
async def lcm(interaction: discord.Interaction): 
    await interaction.response.send_message(file=discord.File("LoveCherryMotion.mp4"))

额外排查点

  • 确认LoveCherryMotion.mp4文件和机器人脚本在同一目录,或者使用完整的绝对文件路径。
  • 检查机器人在目标频道是否拥有发送附件的权限,频道本身是否允许上传文件。

内容的提问来源于stack exchange,提问作者sonhyeju.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 18:22:01