如何在 Discord.js 中创建一个 say 嵌入命令

时间:2021-07-09 06:06:09

标签: discord discord.js bots

我是编码新手,正在为朋友制作一个 Discord 机器人。他们正在请求一个可以作为忏悔命令的 say 命令,它看起来像这样。一个带有设置标题、设置颜色和完全匿名的嵌入,但带有可编辑的描述,可以填充他们想要承认的内容。由于我是编码新手,我不知道该怎么做。如果有人可以提供帮助,那将不胜感激!谢谢!

(编辑)我意识到我对代码的内容还不够了解,所以我用我的 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');
 

所以如果可能的话,任何人都可以给我高级命令处理程序说嵌入命令。谢谢!!

2 个答案:

答案 0 :(得分:1)

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

检查 here 以了解如何创建嵌入。

答案 1 :(得分:1)

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

// 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