【问题标题】:Discord.js bot sending two memes from different redditsDiscord.js 机器人从不同的 reddit 发送两个模因
【发布时间】:2021-02-22 06:16:36
【问题描述】:

所以基本上,我正在尝试让我的 discord 机器人从 r/marvelmemes 发送 meme,因为该机器人用于 MCU 主题服务器。我按照教程创建了我的代码,在教程中,编码器使用了 r/memes。我只改变了一件事。我改变了这一行:

got('https://www.reddit.com/r/memes/random/.json').then(response => {

进入这个:

got('https://www.reddit.com/r/marvelmemes/random/.json').then(response => {

这就是我对原始教程所做的全部更改。当我尝试运行该机器人时,它实际上确实从 r/marvelmemes 发送了一个 meme。但是,它也会从 r/memes 发送一个 meme。它发送了两个模因。我怎样才能让它只从 r/marvelmemes 发送一个模因?这是完整的代码。

const got = require ('got');
module.exports = {
    name: 'meme',
    description: "send a meme",
    execute(message, args, Discord) {
        const embed = new Discord.MessageEmbed()
        got('https://www.reddit.com/r/marvelmemes/random/.json').then(response => {
            let content = JSON.parse(response.body);
            let permalink = content[0].data.children[0].data.permalink;
            let memeUrl = `https://reddit.com${permalink}`;
            let memeImage = content[0].data.children[0].data.url;
            let memeTitle = content[0].data.children[0].data.title;
            let memeUpvotes = content[0].data.children[0].data.ups;
            let memeDownvotes = content[0].data.children[0].data.downs;
            let memeNumComments = content[0].data.children[0].data.num_comments;
            embed.setTitle(`${memeTitle}`)
            embed.setURL(`${memeUrl}`)
            embed.setImage(memeImage)
            embed.setColor('RANDOM')
            embed.setFooter(`???? ${memeUpvotes} ???? ${memeDownvotes} ???? ${memeNumComments}`)
            message.channel.send(embed);
        })
    }
}

我使用了一个基本的命令处理程序,如果它有帮助的话,它看起来像这样:

client.on('message', message => {
    if (!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    if (command == 'meme') {
        client.commands.get('meme').execute(message, args, Discord);
    }

任何帮助将不胜感激!

【问题讨论】:

  • 对我来说似乎工作正常;正如预期的那样,上面的代码只发送一个模因。

标签: javascript discord.js


【解决方案1】:

我很确定您有第二个机器人正在运行,因为有多个终端。

如果你有 Visual Studio Code,你可以在这里看到它们: 在这里你可以删除终端(红框)

【讨论】:

    猜你喜欢
    • 2021-01-09
    • 2022-01-24
    • 2021-04-07
    • 1970-01-01
    • 2021-05-08
    • 2021-03-11
    • 2021-08-09
    • 2020-09-15
    • 2019-09-20
    相关资源
    最近更新 更多