【问题标题】:Discord.js send a medium post to a discord channelDiscord.js 将中等帖子发送到不和谐频道
【发布时间】:2021-11-05 18:07:34
【问题描述】:

我想尝试将媒体的帖子链接发送到不和谐频道。但是我没有在网上找到太多资源。我找到了一些 SDK 库,但这似乎真的已经过时了https://www.npmjs.com/package/medium-sdk。是否可以以某种方式使用 Medium API 将来自某些“用户”的媒体帖子作为媒体帖子网站链接发送到定义的不和谐频道? 不确定是否有人这样做过。当不和谐消息以某种方式发送到频道时,我只看到了创建中等帖子的可能性。但这不是我想要的。

【问题讨论】:

  • 您是否正在寻找如何在 Medium 用户发布新文章时发送 Discord 消息?
  • @user15517071 没错!

标签: node.js discord.js integration social medium.com


【解决方案1】:

您可以使用这个包:feed-watcher,并将提要设置为https://medium.com/feed/@the_writer_name

美好的一天

【讨论】:

  • 您好!我试图实现它,但是我没有得到关于新提要的任何更新,而且我在启动时遇到了奇怪的错误(我只会在脚本启动时收到一些数据)node test.js Error: Invalid URI "rasmont.medium.com/feed?unit=second&interval=5"
  • 我有一个问题stackoverflow.com/questions/69147878/…。我不知道如何从响应中获取数据,以便我可以使用它们。
【解决方案2】:

这样,您可以从 feed-watcher 获取媒体帖子,然后将来自媒体帖子的链接发送到不和谐频道。 (Feed 大约每 15-20 分钟更新一次。)因此,一旦发布中型帖子以接收来自 Feed 的数据以发送链接到频道,则可能会有延迟。

'use strict';

//define your medium link in the feed
var Watcher = require('feed-watcher'),
feed = "https://yourmedium.medium.com/feed?unit=second&interval=5",
interval = 10 // seconds

var watcher = new Watcher(feed, interval)

// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const config = require("./configtest.json");

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

client.on('ready', () => {
  watcher.on('new entries', function (entries) {
    entries.forEach(function (entry) {
      const stringifylink = JSON.stringify(entry)
      const link = JSON.parse(stringifylink)
      console.log('FEED Call response:', link);
      console.log('Link:', link.link)
      //send new medium post link to the defined discord channel. 
      client.guilds.cache.forEach(guild => {
      let channel = guild.channels.cache.get('ChannelID')
      channel.send('Check out our new medium post! ' + link.link)
      })
    })
  })
  watcher
  .start()
  .then(function (entries) {
    console.log(entries)
  })
  .catch(function(error) {
    console.error(error)
  })
})

// Login to Discord with your client's token
client.login(config.token);

【讨论】:

    猜你喜欢
    • 2020-11-06
    • 1970-01-01
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 2019-04-11
    • 2019-07-10
    • 2020-11-23
    相关资源
    最近更新 更多