如何在Discord.js中生成say-embed命令



我是编码新手,正在为一个朋友制作Discord机器人。他们要求一个发言权命令,在看起来像这样的情况下,可以充当认罪命令。一个具有设置的标题、设置的颜色和完全匿名的嵌入,但具有可编辑的描述,可以填充他们想要坦白的内容。由于我是编码新手,我不知道如何做到这一点。如果有人能帮忙,我们将不胜感激!非常感谢。

(编辑(我意识到我对代码还不够了解,所以我用我的main.js代码进行了编辑。


const client = new Discord.Client();
const prefix = 'wtf ';
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);
}


bot.once('ready', () => {
console.log('Tomoko is online!');
});

bot.on('message', async msg =>{
if(!msg.content.startsWith(prefix) || msg.author.bot) return;

const args = msg.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();

if(command === 'ping'){
client.commands.get('ping').execute(msg, args, Discord);
} else if (command === 'creator'){
client.commands.get('creator').execute(msg, args, Discord);
} else if (command === 'help'){
client.commands.get('help').execute(msg, args, Discord);
} else if (command === 'kick'){
client.commands.get('kick').execute(msg, args, Discord);
} else if (command === 'ban'){
client.commands.get('ban').execute(msg, args, Discord);
} else if (command === 'mute'){
client.commands.get('mute').execute(msg, args, Discord);
} else if (command === 'unmute'){
client.commands.get('unmute').execute(msg, args, Discord);
} else if (command === 'warn'){
client.commands.get('warn').execute(msg, args)
} else if (command === 'deletewarns'){
client.commands.get('deletewarns').execute(msg, args);
} else if (command === 'warnings'){
client.commands.get('warnings').execute(msg, args);
}     if (args[0].toLowerCase() === 'confess') {
const description = args.splice(1).join(" ");
const embed = new MessageEmbed().setTitle('✦┊‧๑ ꒰<a:ccc:862524564457390150><a:ooo:862524674185101322><a:nnn:862524667368833024><a:fff:862524592202973244><a:eee:862524583802568714><a:sss:862524709782683648><a:sss:862524709782683648>꒱ ‧๑┊✧').setColor('ffaaaa').setDescription(description);
await msg.delete().catch(e => console.log(e));
msg.channel.send(embed);
} else if (command === "unban"){
client.commands.get('unban').execute(msg, args, Discord);

;}
});

client.login('DAMN YOU WISH I WOULD SHOW YOU');

所以,如果可能的话,任何人都可以给我高级的命令处理程序,比如嵌入式命令。非常感谢。

这取决于您如何处理命令。但一般来说:生成一个新的嵌入,并将描述设置为消息的内容。

请在此处查看如何创建嵌入。

一个简单的机器人来完成你的工作

// importing dependencies
const { MessageEmbed, Client } = require('discord.js');
const prefix = '!';
const bot = new Client(); // init discord client
bot.on('ready', () => console.log('yee im on'));
// listening for messages
bot.on('message', async msg => {
if (!msg.content.startsWith(prefix)) return // dont run if the prefix is not used
const args = msg.content.substring(prefix.length).split(" "); // creating array of the message contents
if (args[0].toLowerCase() === 'say') { // a simple command handler
const description = args.splice(1).join(" ");
const embed = new MessageEmbed().setDescription(description); // setTitle and stuff according to your preference
await msg.delete().catch(e => console.log(e)); // deleting the user message since it should be anonymous
msg.channel.send(embed);
}
});
bot.login('yourtokenhere');

确保用您的令牌和前缀替换令牌和前缀

如何运行命令:

!say ooh this is a confession

最新更新