使用 discord.js 将提供的数据中的随机项目发送到不和谐嵌入
Send Random items from provided data to discord embed using discord.js
我正在尝试制作一个可以根据提供的数据发送随机项目的不和谐机器人。一切运行顺利,但我想以嵌入的形式发送这些项目,但我找不到办法做到这一点。我在下面附上我的代码
const jokes = [
'I went to a street where the houses were numbered 8k, 16k, 32k, 64k, 128k, 256k and 512k. It was a trip down Memory Lane.',
'“Debugging” is like being the detective in a crime drama where you are also the murderer.',
'The best thing about a Boolean is that even if you are wrong, you are only off by a bit.',
'A programmer puts two glasses on his bedside table before going to sleep. A full one, in case he gets thirsty, and an empty one, in case he doesnt.',
'If you listen to a UNIX shell, can you hear the C?',
'Why do Java programmers have to wear glasses? Because they dont C#.',
'What sits on your shoulder and says “Pieces of 7! Pieces of 7!”? A Parroty Error.',
'When Apple employees die, does their life HTML5 in front of their eyes?',
'Without requirements or design, programming is the art of adding bugs to an empty text file.',
'Before software can be reusable it first has to be usable.',
'The best method for accelerating a computer is the one that boosts it by 9.8 m/s2.',
'I think Microsoft named .Net so it wouldnt show up in a Unix directory listing.',
'There are two ways to write error-free programs; only the third one works.',
];
module.exports={
name:'joke',
execute(message, arg){
message.channel.send(jokes[Math.floor(Math.random() * jokes.length)]);
}
}
const { MessageEmbed } = require('discord.js');
const embed = new MessageEmbed().setDescription(jokes[Math.floor(Math.random() * jokes.length)]);
message.channel.send({embeds: [embed]});
https://discord.js.org/#/docs/discord.js/stable/class/MessageEmbed
const jokes = [
'I went to a street where the houses were numbered 8k, 16k, 32k, 64k, 128k, 256k and 512k. It was a trip down Memory Lane.',
'“Debugging” is like being the detective in a crime drama where you are also the murderer.',
'The best thing about a Boolean is that even if you are wrong, you are only off by a bit.',
'A programmer puts two glasses on his bedside table before going to sleep. A full one, in case he gets thirsty, and an empty one, in case he doesnt.',
'If you listen to a UNIX shell, can you hear the C?',
'Why do Java programmers have to wear glasses? Because they dont C#.',
'What sits on your shoulder and says “Pieces of 7! Pieces of 7!”? A Parroty Error.',
'When Apple employees die, does their life HTML5 in front of their eyes?',
'Without requirements or design, programming is the art of adding bugs to an empty text file.',
'Before software can be reusable it first has to be usable.',
'The best method for accelerating a computer is the one that boosts it by 9.8 m/s2.',
'I think Microsoft named .Net so it wouldnt show up in a Unix directory listing.',
'There are two ways to write error-free programs; only the third one works.',
];
const embed = new MessageEmbed()
.setTitle('Title here')
.setDescription(jokes[Math.floor(Math.random() * jokes.length)])
.setColor('color_here')
message.channel.send({embeds: [embed]})
//message.reply({embeds: [embed]})
我正在尝试制作一个可以根据提供的数据发送随机项目的不和谐机器人。一切运行顺利,但我想以嵌入的形式发送这些项目,但我找不到办法做到这一点。我在下面附上我的代码
const jokes = [
'I went to a street where the houses were numbered 8k, 16k, 32k, 64k, 128k, 256k and 512k. It was a trip down Memory Lane.',
'“Debugging” is like being the detective in a crime drama where you are also the murderer.',
'The best thing about a Boolean is that even if you are wrong, you are only off by a bit.',
'A programmer puts two glasses on his bedside table before going to sleep. A full one, in case he gets thirsty, and an empty one, in case he doesnt.',
'If you listen to a UNIX shell, can you hear the C?',
'Why do Java programmers have to wear glasses? Because they dont C#.',
'What sits on your shoulder and says “Pieces of 7! Pieces of 7!”? A Parroty Error.',
'When Apple employees die, does their life HTML5 in front of their eyes?',
'Without requirements or design, programming is the art of adding bugs to an empty text file.',
'Before software can be reusable it first has to be usable.',
'The best method for accelerating a computer is the one that boosts it by 9.8 m/s2.',
'I think Microsoft named .Net so it wouldnt show up in a Unix directory listing.',
'There are two ways to write error-free programs; only the third one works.',
];
module.exports={
name:'joke',
execute(message, arg){
message.channel.send(jokes[Math.floor(Math.random() * jokes.length)]);
}
}
const { MessageEmbed } = require('discord.js');
const embed = new MessageEmbed().setDescription(jokes[Math.floor(Math.random() * jokes.length)]);
message.channel.send({embeds: [embed]});
https://discord.js.org/#/docs/discord.js/stable/class/MessageEmbed
const jokes = [
'I went to a street where the houses were numbered 8k, 16k, 32k, 64k, 128k, 256k and 512k. It was a trip down Memory Lane.',
'“Debugging” is like being the detective in a crime drama where you are also the murderer.',
'The best thing about a Boolean is that even if you are wrong, you are only off by a bit.',
'A programmer puts two glasses on his bedside table before going to sleep. A full one, in case he gets thirsty, and an empty one, in case he doesnt.',
'If you listen to a UNIX shell, can you hear the C?',
'Why do Java programmers have to wear glasses? Because they dont C#.',
'What sits on your shoulder and says “Pieces of 7! Pieces of 7!”? A Parroty Error.',
'When Apple employees die, does their life HTML5 in front of their eyes?',
'Without requirements or design, programming is the art of adding bugs to an empty text file.',
'Before software can be reusable it first has to be usable.',
'The best method for accelerating a computer is the one that boosts it by 9.8 m/s2.',
'I think Microsoft named .Net so it wouldnt show up in a Unix directory listing.',
'There are two ways to write error-free programs; only the third one works.',
];
const embed = new MessageEmbed()
.setTitle('Title here')
.setDescription(jokes[Math.floor(Math.random() * jokes.length)])
.setColor('color_here')
message.channel.send({embeds: [embed]})
//message.reply({embeds: [embed]})