随机Meme命令(discord.js v12)

随机Meme命令(discord.js v12),discord.js,Discord.js,我正在尝试为我的Discord机器人制作一个“随机模因”命令。我不熟悉使用API,但我已经尽力了 问题是,当我键入命令时,什么也没有发生。没有错误,但bot不会发送任何不一致的内容 这是我的代码: if(命令==“meme”) 异步(客户端、消息、参数)=>{ const subReddits=[“dankmeme”、“meme”、“me_irl”]; const random=subReddits[Math.floor(Math.random()*subReddits.length)]; 常数

我正在尝试为我的Discord机器人制作一个“随机模因”命令。我不熟悉使用API,但我已经尽力了

问题是,当我键入命令时,什么也没有发生。没有错误,但bot不会发送任何不一致的内容

这是我的代码:

if(命令==“meme”)
异步(客户端、消息、参数)=>{
const subReddits=[“dankmeme”、“meme”、“me_irl”];
const random=subReddits[Math.floor(Math.random()*subReddits.length)];
常数img=等待随机(随机);
const embed=new Discord.MessageEmbed()
.setColor(16776960)
.setFooter(“测试”)
.setImage(img)
.setTitle(`Random Meme requested by`)
.setURL(`https://reddit.com/r/${random}`)
message.channel.send(嵌入);
}
client.on('message',message=>{
如果(!message.content.startsWith(prefix)| | message.author.bot)返回;
const args=message.content.slice(prefix.length.trim().split(+/);
const命令=args.shift().toLowerCase();
如果(命令==“meme”){
异步(客户端、消息、参数)=>
const subReddits=[“dankmeme”、“meme”、“me_irl”];
const random=subReddits[Math.floor(Math.random()*subReddits.length)];
常数img=等待随机(随机);
const embed=new Discord.MessageEmbed()
.setColor(16776960)
.setFooter(“测试”)
.setImage(img)
.setTitle(`Random Meme requested by`)
.setURL(`https://reddit.com/r/${random}`)
message.channel.send(嵌入);
}
}); 
这应该可以,不太确定,还没有测试过。(您可以自己放入命令处理程序)

client.on('message',message=>{
如果(!message.content.startsWith(prefix)| | message.author.bot)返回;
const args=message.content.slice(prefix.length.trim().split(+/);
const命令=args.shift().toLowerCase();
如果(命令==“meme”){
异步(客户端、消息、参数)=>
const subReddits=[“dankmeme”、“meme”、“me_irl”];
const random=subReddits[Math.floor(Math.random()*subReddits.length)];
常数img=等待随机(随机);
const embed=new Discord.MessageEmbed()
.setColor(16776960)
.setFooter(“测试”)
.setImage(img)
.setTitle(`Random Meme requested by`)
.setURL(`https://reddit.com/r/${random}`)
message.channel.send(嵌入);
}
}); 

这应该可以,不太确定,还没有测试过。(你可以自己设置一个命令处理程序)

这里有一个可以显示有关Meme的信息

if(command === "meme") {
const subReddits = ["dankmeme", "meme", "me_irl"];
const random = subReddits[Math.floor(Math.random() * subReddits.length)];
try {
const { body } = await snekfetch
                .get('https://www.reddit.com/r/${random}.json?sort=top&t=week')
                .query({ limit: 800 });
const allowed = message.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
if (!allowed.length) return message.channel.send('It seems we are out of memes');
const randomnumber = Math.floor(Math.random() * allowed.length)
const embed = new Discord.RichEmbed()
            .setColor(0x00A2E8)
            .setTitle(allowed[randomnumber].data.title)
            .setDescription("Posted by: " + allowed[randomnumber].data.author)
            .setImage(allowed[randomnumber].data.url)
            .addField("Other info:", "Up votes: " + allowed[randomnumber].data.ups + " / Comments: " + allowed[randomnumber].data.num_comments)
            .setFooter("r/" + random)
message.channel.send(embed)
        } catch (err) {
return console.log(err);
        }
    }

如果它不起作用,请告诉我,但我应该

这里有一个将显示有关Meme的信息

if(command === "meme") {
const subReddits = ["dankmeme", "meme", "me_irl"];
const random = subReddits[Math.floor(Math.random() * subReddits.length)];
try {
const { body } = await snekfetch
                .get('https://www.reddit.com/r/${random}.json?sort=top&t=week')
                .query({ limit: 800 });
const allowed = message.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
if (!allowed.length) return message.channel.send('It seems we are out of memes');
const randomnumber = Math.floor(Math.random() * allowed.length)
const embed = new Discord.RichEmbed()
            .setColor(0x00A2E8)
            .setTitle(allowed[randomnumber].data.title)
            .setDescription("Posted by: " + allowed[randomnumber].data.author)
            .setImage(allowed[randomnumber].data.url)
            .addField("Other info:", "Up votes: " + allowed[randomnumber].data.ups + " / Comments: " + allowed[randomnumber].data.num_comments)
            .setFooter("r/" + random)
message.channel.send(embed)
        } catch (err) {
return console.log(err);
        }
    }

如果它不起作用,请告诉我,但我应该

这是一个匿名异步函数,您是否有命令处理程序,并打算将其命名为
run
execute
?如果没有,并且它在你的主文件或其他文件中,它永远不会运行,因为它不是一个生命。无论哪种方式显示更多上下文代码这是一个匿名异步函数,您是否有命令处理程序,并打算将其命名为
run
execute
?如果没有,并且它在你的主文件或其他文件中,它永远不会运行,因为它不是一个生命。无论哪种方式,都会显示更多的上下文代码