【发布时间】:2020-12-17 09:55:45
【问题描述】:
我想创建一个不和谐的机器人,当有人键入 -ping 时,它会给出一个嵌入的超链接。
我的当前代码是:
“嵌入.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 岁或橡皮鸭一样解释。
【问题讨论】:
标签: javascript discord bots