有人能说出为什么我的Meme生成器代码不起作用吗?因此,我在discord.js中制作了一个模因生成器,当有人说"gg! meme“时,它会生成随机模因。
client.on('message', message => {
module.exports = {
name: "meme",
category: "fun",
description: "Sends an epic meme",
run: async (client, message, args) => {
// In this array,
// you can put the subreddits you want to grab memes from
const subReddits = ["dankmeme", "meme", "me_irl"];
// Grab a random property from the array
const random = subReddits[Math.floor(Math.random() * subReddits.length)];
if (message.content === 'gg!meme') {
// Get a random image from the subreddit page
const img = await randomPuppy(random);
const embed = new RichEmbed()
.setColor("RANDOM")
.setImage(img)
.setTitle(`From /r/${random}`)
.setURL(`https://reddit.com/r/${random}`);
message.channel.send(embed);
}
}
};
});
发布于 2020-12-25 15:16:50
概述:是的,我知道原因。看起来,您已经完全复制并粘贴了代码源代码,并将其放入代码中,而不知道它在做什么。
问题:您已经在非命令处理程序脚本中输入了命令处理程序结构化命令。
问题:#2这段代码过时了,似乎是Discord.js v11
假设您的脚本是在没有命令处理程序的情况下运行的,那么应该可以这样做:
client.on('message', message => {
if (message.content === 'gg!meme') {
// In this array,
// you can put the subreddits you want to grab memes from
const subReddits = ["dankmeme", "meme", "me_irl"];
// Grab a random property from the array
const random = subReddits[Math.floor(Math.random() * subReddits.length)];
// Get a random image from the subreddit page
const img = await randomPuppy(random);
const embed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setImage(img)
.setTitle(`From /r/${random}`)
.setURL(`https://reddit.com/r/${random}`);
message.channel.send(embed);
}
});
建议:
与其每次发出命令时都输入gg!
,不如将其转换为可以始终引用的变量。
Example:
const prefix = 'gg!'
Usage:
if (message.content.startsWith(prefix + 'ping')) {
return message.channel.send('pong!')
}
假设您也安装了npm包randompuppy
,这应该可以工作。
发布于 2020-12-25 15:18:01
您使用的是过时的discord.js版本。
通过在终端中键入discord.js来安装最新版本的npm i discord.js@latest
。在最新版本中,RichEmbed
被MessageEmbed
取代。
https://stackoverflow.com/questions/65452135
复制相似问题