Randompuppys不会在discord.js上从reddit获取图像

Randompuppys不会在discord.js上从reddit获取图像,discord,discord.js,Discord,Discord.js,我正试图让Discord.js机器人从Reddit抓取图像并发布到一个频道,但它一直说没有内容可发送,我想知道是否有人能指出我做错了什么 (我正在使用命令处理程序) 代码: 当我尝试使用随机小狗从r/dankmemes中获取图像时,其中很多是GIF或视频。确保使用了正确的扩展名,并增加了restRequestTimeout,以便为文件发送留出时间 Discord.js中的属性文件在v11中被弃用,并在v12中被删除。您应该使用文件 你应该用它来代替 使用此选项初始化客户端,将超时设置为1分钟

我正试图让Discord.js机器人从Reddit抓取图像并发布到一个频道,但它一直说没有内容可发送,我想知道是否有人能指出我做错了什么

(我正在使用命令处理程序)

代码:

  • 当我尝试使用随机小狗从r/dankmemes中获取图像时,其中很多是GIF或视频。确保使用了正确的扩展名,并增加了
    restRequestTimeout
    ,以便为文件发送留出时间
  • Discord.js中的属性
    文件
    在v11中被弃用,并在v12中被删除。您应该使用
    文件
  • 你应该用它来代替
使用此选项初始化客户端,将超时设置为1分钟,而不是默认的15秒:

const client = new Client({restRequestTimeout: 60000})
在命令文件中:

// returns .jpg, .png, .gif, .mp4 etc
// for more info see https://nodejs.org/api/path.html#path_path_extname_path
const {extname} = require('path')
const fetch = require('node-fetch')

/* ... */

// in your run function
// you can use thens if you want but I find this easier to read
try {
  const url = await randomPuppy(subreddit)
  const res = await fetch(url)
  await Message.channel.send({
    files: [{
      attachment: res.body,
      name: `image${extname(url)}`
    }]
  })
} catch (err) {
  console.error(err)
}

我照你说的做了,但现在它只给我默认图像,而不是子Reddit图像
// returns .jpg, .png, .gif, .mp4 etc
// for more info see https://nodejs.org/api/path.html#path_path_extname_path
const {extname} = require('path')
const fetch = require('node-fetch')

/* ... */

// in your run function
// you can use thens if you want but I find this easier to read
try {
  const url = await randomPuppy(subreddit)
  const res = await fetch(url)
  await Message.channel.send({
    files: [{
      attachment: res.body,
      name: `image${extname(url)}`
    }]
  })
} catch (err) {
  console.error(err)
}