首页 > 解决方案 > 将 DMed 文件和链接发送到服务器中的频道

问题描述

好的。这可能是一个奇怪的问题,但我需要帮助,因为我在网上找不到任何东西。我有一个不和谐的机器人和服务器来举办比赛,用户通过直接向我发送他们提交的链接或文件来提交他们的提交。我想将其更改为他们对机器人进行 DM,然后机器人将链接和文件发布到服务器的某个频道中。我完全不知道如何实现这一点,因为当涉及到这类事情时,我是一个新手。如果我需要更改措辞或需要澄清任何事情,请发表评论!

标签: discorddiscord.js

解决方案


替换channel id为您要将提交发送到的频道的实际 ID。

对于 Discord.js v12/v13(最新版本):

client.on('message', ({attachments, author, content, guild}) => {
  // only do this for DMs
  if (!guild) {
    // this will simply send all the attachments, if there are any, or the message content
    // you might also want to check that the content is a link as well
    const submission = attachments.size
      ? {files: [...attachments.values()], content: `${author}`}
      : {content: `${content}\n${author}`}
    client.channels.cache.get('channel id').send(submission)
  }
})

对于 Discord.js v11 替换

client.channels.cache.get('channel id').send(submission)

client.channels.get('channel id').send(submission)

推荐阅读