【问题标题】:How to make a say embed command in Discord.js如何在 Discord.js 中创建说嵌入命令
【发布时间】:2023-04-03 08:15:01
【问题描述】:

我是编码新手,正在为朋友制作 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');
 

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

【问题讨论】:

    标签: discord discord.js bots


    【解决方案1】:

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

    查看here 了解如何创建嵌入。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2020-07-14
        • 1970-01-01
        • 2021-11-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-09-30
        • 2022-10-22
        • 1970-01-01
        相关资源
        最近更新 更多