简体   繁体   English

如何使用 discord.js 进行嵌入

[英]How to make an embed with discord.js

I was wondering how to write an embed in discord.js .我想知道如何在discord.js中编写嵌入。 This is my current code: it is not functional.这是我当前的代码:它不起作用。 I get the warning: 'message is not defined' on message.channel.send I do not know how to fix this.我收到警告: message.channel.send上的“消息未定义”我不知道如何解决这个问题。 I was hoping you guys could tell me how to fix this.我希望你们能告诉我如何解决这个问题。 js js

message.channel.send(generateEmbed(0)).then((message) => {
  if (guilds.length <= 10) return;

  message.react(":right_arrow:");
  const collector = message.createReactionCollector(
    (reaction, user) =>
      [":left_arrow:", ":right_arrow"].includes(reaction.emoji.name) &&
      user.id === message.author.id,
    // time out after a minute
    { time: 60000 }
  );

  let currentIndex = 0;
  collector.on("collect", (reaction) => {
    message.reactions.removeAll().then(async () => {
      reaction.emoji.name === ":left_emoji:"
        ? (currentIndex -= 10)
        : (currentIndex += 10);

      message.edit(generateEmbed(currentIndex));

      if (currentIndex !== 0) await message.react(":left_arrow:");
      // react with right arrow if it isn't the end
      if (currentIndex + 10 < guilds.length) message.react(":right_arrow:");
    });
  });
});

bot.login(token);

I was wondering how to write an embed in discord.js .我想知道如何在discord.js中编写嵌入。 This is my current code: it is not functional.这是我当前的代码:它不起作用。 I get the warning: 'message is not defined' on message.channel.send I do not know how to fix this.我收到警告: message.channel.send上的“消息未定义”我不知道如何解决这个问题。 I was hoping you guys could tell me how to fix this.我希望你们能告诉我如何解决这个问题。 js js

message.channel.send(generateEmbed(0)).then((message) => {
  if (guilds.length <= 10) return;

  message.react(":right_arrow:");
  const collector = message.createReactionCollector(
    (reaction, user) =>
      [":left_arrow:", ":right_arrow"].includes(reaction.emoji.name) &&
      user.id === message.author.id,
    // time out after a minute
    { time: 60000 }
  );

  let currentIndex = 0;
  collector.on("collect", (reaction) => {
    message.reactions.removeAll().then(async () => {
      reaction.emoji.name === ":left_emoji:"
        ? (currentIndex -= 10)
        : (currentIndex += 10);

      message.edit(generateEmbed(currentIndex));

      if (currentIndex !== 0) await message.react(":left_arrow:");
      // react with right arrow if it isn't the end
      if (currentIndex + 10 < guilds.length) message.react(":right_arrow:");
    });
  });
});

bot.login(token);

I was wondering how to write an embed in discord.js .我想知道如何在discord.js中编写嵌入。 This is my current code: it is not functional.这是我当前的代码:它不起作用。 I get the warning: 'message is not defined' on message.channel.send I do not know how to fix this.我收到警告: message.channel.send上的“消息未定义”我不知道如何解决这个问题。 I was hoping you guys could tell me how to fix this.我希望你们能告诉我如何解决这个问题。 js js

message.channel.send(generateEmbed(0)).then((message) => {
  if (guilds.length <= 10) return;

  message.react(":right_arrow:");
  const collector = message.createReactionCollector(
    (reaction, user) =>
      [":left_arrow:", ":right_arrow"].includes(reaction.emoji.name) &&
      user.id === message.author.id,
    // time out after a minute
    { time: 60000 }
  );

  let currentIndex = 0;
  collector.on("collect", (reaction) => {
    message.reactions.removeAll().then(async () => {
      reaction.emoji.name === ":left_emoji:"
        ? (currentIndex -= 10)
        : (currentIndex += 10);

      message.edit(generateEmbed(currentIndex));

      if (currentIndex !== 0) await message.react(":left_arrow:");
      // react with right arrow if it isn't the end
      if (currentIndex + 10 < guilds.length) message.react(":right_arrow:");
    });
  });
});

bot.login(token);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM