【问题标题】:How do I get my discord bot to send a random meme/picture如何让我的不和谐机器人发送随机模因/图片
【发布时间】:2021-06-04 18:18:12
【问题描述】:

如何让我的机器人发送不和谐的随机图片/模因。我正在使用 discord.js,目前为止。

  if (msg.content === '-meme');
  var randommeme = ({files:["https://cdn.discordapp.com/attachments/757397429107556422/757524795452686426/GBoat_Watermark.png"]} , {files:["https://cdn.discordapp.com/attachments/815040456244985947/816225078969892864/A_good_fluffy_goat.png"]});
  var fact = Math.floor(Math.random() * randommeme.length); 
  msg.channel.send('goat meme', randommeme[fact]);
});

这应该会发送一张随机图片,但是当我运行该命令时,它只会显示“goat meme”。我之前尝试过这段代码,它成功了。

client.on('message', msg => {
  if (msg.content === '+meme') {
  msg.channel.send("This is a good fluffy goat", {files: ["https://cdn.discordapp.com/attachments/757397429107556422/816234172737126430/A_good_fluffy_goat.png","https://cdn.discordapp.com/attachments/757397429107556422/757524795452686426/GBoat_Watermark.png"]});
  }
});

我真的不知道我在这里做错了什么?

【问题讨论】:

    标签: image random discord discord.js bots


    【解决方案1】:

    首先创建一个链接数组,然后使用 random 函数从数组中获取随机链接。

    const meme = ['link_1','link_2','link_3','link_4'];
    const index = Math.floor(Math.random() * meme.length);
    message.channel.send('Goat meme',{files:[meme[index]]});
    

    其中 link_1、link_2 等为附件 URL。

    【讨论】:

      【解决方案2】:

      第二行有错别字,正确的代码应该是这样的:

      var randommeme = ({files:["https://cdn.discordapp.com/attachments/757397429107556422/757524795452686426/GBoat_Watermark.png", "https://cdn.discordapp.com/attachments/815040456244985947/816225078969892864/A_good_fluffy_goat.png"]});
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-08
        • 2020-10-01
        • 2017-11-19
        • 2021-04-26
        • 2021-04-30
        • 2021-05-08
        • 2020-12-26
        • 2021-04-25
        相关资源
        最近更新 更多