我想创建一个discord bot,当有人键入-ping时,它会发出一个嵌入的超链接。
我当前拥有的代码是:
“ embed.js”
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '-';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('embed is online!');
});
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 == 'ping'){
Discord.MessageEmbed.channel.send(exampleEmbed)
}
});
client.login('NzQ4ODQ3MzYwMjA5MzIxOTg0.X0jYcw.fZjcPUwrpEQPkQyqQdxprCYVH6g');
“ ping.js”
const Discord = require('discord.js');
const exampleEmbed = new Discord.MessageEmbed();
exampleEmbed.setTitle('Some title');
exampleEmbed.setURL('https://discord.js.org/');
Discord.Message.channel.send(exampleEmbed);
我正在尝试遵循以下条件:
https://discordjs.guide/popular-topics/embeds.html#embed-preview 有了本指南, https://www.youtube.com/watch?v=AUOb9_aAk7U&list=PLbbLC0BLaGjpyzN1rg-gK4dUqbn8eJQq4&index=3
欢迎您提供任何帮助或思考,但请像5岁或橡皮鸭一样对其进行解释。
答案 0 :(得分:0)
似乎您具有正确的代码,以便进行嵌入,但是您需要使用Discord.Message.channel.send({ embed: exampleEmbed });
此外,我建议您重新生成机器人令牌here,因为它允许任何人控制您的机器人。