JavaScript Discord.js akinatör yapımı

asd674

Kilopat
Katılım
13 Nisan 2020
Mesajlar
4.884
Makaleler
2
Çözümler
70
Yer
Elbistan
Daha fazla  
Sistem Özellikleri
Excalibur g770 İ7 9750H GTX 1050 16 gb ram 500 gb 970 evo plus 1tb toshiba hdwl110
Cinsiyet
Erkek
Meslek
Öğrenci
Discord.js ile akinatör yapmak istiyorum. Akinatörün sorusunu atmaya kadar geldim. Bundan sonra buton oluşturup onlarla yanıt almak istiyorum. Ancak nasıl yapabileceğimi çözemedim.

JavaScript:
const {
  ApplicationCommandType,
  ApplicationCommandOptionType,
  ChannelType,
  REST,
  Routes,
  Client,
  ChannelSelectMenuInteraction,
  ButtonBuilder,
  ActionRowBuilder,
  ButtonStyle,
  Events,
  ButtonInteraction,
  InteractionType,
  InteractionResponse,
  createChannel,
  CategoryChannel,
  PermissionOverwrites,
  PermissionsBitField,
  ModalSubmitFields,
  time,
  GatewayIntentBits,
  EmbedBuilder,
  Collection,
  VoiceChannel,
  ActivityType,
} = require("discord.js");
const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildVoiceStates,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
  ],
});
const transcripts = require("discord-html-transcripts");
const deletembed = new EmbedBuilder().setColor("Gold").setTitle("Silindi");
const { Aki } = require("aki-api");
const config = require("./config.json");
const commands = [
  {
    name: "clear",
    description: "Bulk delete messages",
    options: [
      {
        name: "amount",
        description: "Amount bulk delete messages",
        required: true,
        type: ApplicationCommandOptionType.Number,
      },
    ],
  },
  ,
  {
    name: "akinator",
    description: "Start akinator",
  },
];

const rest = new REST({ version: "10" }).setToken(config.token);

(async () => {
  try {
    console.log("Started refreshing application (/) commands.");

    await rest.put(Routes.applicationCommands("1094167353417281586"), {
      body: commands,
    });

    console.log("Successfully reloaded application (/) commands.");
  } catch (error) {
    console.error(error);
  }
})();

client.on("interactionCreate", async (interaction) => {
  if (!interaction.isChatInputCommand()) return;
  if (interaction.memberPermissions.has("Administrator")) {
    if (interaction.commandName === "clear") {
      const deger = interaction.options.getNumber("amount");
      const sebep = interaction.options.getString("reason", false);
      const hedefkisi = interaction.options.getUser("target", false);
      const ChannelMessages = interaction.channel.messages.fetch();
      const logchannel = interaction.guild.channels.cache.get(
        "1094902994325209110"
      );
      const logembed = new EmbedBuilder()
        .setColor("DarkAqua")
        .setAuthor({ name: "CLEAR COMMAND USED" });
      if (deger < 101) {
        let logembeddescription = [
          `Moderator:${interaction.member}`,
          `Target:${hedefkisi || "None"}`,
          `Channel:${interaction.channel}`,
        ];

        const transcript = await transcripts.createTranscript(
          interaction.channel,
          { limit: deger }
        );
        interaction.channel.bulkDelete(deger, true).then((messages) => {
          logembeddescription.push(`Total Messages:${messages.size}`);
          logchannel.send({
            embeds: [logembed.setDescription(logembeddescription.join("\n"))],
            files: [transcript],
          });
        });

        interaction.reply({ embeds: [deletembed] });
      } else {
        interaction.reply("100 den fazla mesaj silemezsiniz.");
      }
    }
  } else {
    interaction.reply("Yönetici değilsin");
  }
  if (interaction.commandName === "satranc") {
    const maks = interaction.options.getInteger("maks", true);
  }
  if (interaction.commandName === "akinator") {
    interaction.reply("We working it");
    const run = async () => {
      const region = "tr";
      const childmode = false;
      const proxy = undefined;
      const aki = new Aki({ region, childmode, proxy });
      await aki.start();
      let sleep = async (ms) => await new Promise((r) => setTimeout(r, ms));
      await sleep(3000);
      interaction.editReply(aki.question);
    };

    run().catch(console.error);
  }
});

client.login(config.token);
 
Son düzenleyen: Moderatör:
Bir örnek vereyim:
JavaScript:
const { Client, MessageActionRow, MessageButton } = require('discord.js');
const { Aki } = require('aki-api');

const client = new Client();
const PREFIX = '!';

client.once('ready', () => {
  console.log('Bot is ready.');
});

client.on('messageCreate', async (message) => {
  if (message.author.bot) return;
  if (!message.content.startsWith(PREFIX)) return;

  const args = message.content.slice(PREFIX.length).trim().split(/ +/);
  const command = args.shift().toLowerCase();

  if (command === 'akinator') {
    const aki = new Aki();
    await aki.start();

    const sendQuestion = async () => {
      await aki.step();

      if (aki.progress >= 70 || aki.currentStep >= 78) {
        // Oyunu bitir ve sonucu gönder
        const result = await aki.win();
        message.channel.send(`Tahminim: ${result.answer}`);
        return;
      }

      // Soruyu gönder ve yanıtlar için düğmeleri oluştur
      const question = aki.question;
      const answers = aki.answers.map((answer, index) => ({
        label: answer,
        value: index.toString(),
      }));

      const row = new MessageActionRow().addComponents(
        new MessageButton()
          .setCustomId('0')
          .setLabel(answers[0].label)
          .setStyle('PRIMARY'),
        new MessageButton()
          .setCustomId('1')
          .setLabel(answers[1].label)
          .setStyle('PRIMARY'),
        new MessageButton()
          .setCustomId('2')
          .setLabel(answers[2].label)
          .setStyle('PRIMARY'),
        new MessageButton()
          .setCustomId('3')
          .setLabel(answers[3].label)
          .setStyle('PRIMARY')
      );

      message.channel.send(question, { components: [row] });
    };

    sendQuestion();
  }
});

client.on('interactionCreate', async (interaction) => {
  if (!interaction.isButton()) return;

  const aki = new Aki();

  if (interaction.customId === '0' || interaction.customId === '1' || interaction.customId === '2' || interaction.customId === '3') {
    const answerIndex = parseInt(interaction.customId);
    await aki.step(answerIndex);

    interaction.update({ components: [] });

    if (aki.progress >= 70 || aki.currentStep >= 78) {
      const result = await aki.win();
      interaction.channel.send(`Tahminim: ${result.answer}`);
      return;
    }

    const sendQuestion = async () => {
      await aki.step();

      const question = aki.question;
      const answers = aki.answers.map((answer, index) => ({
        label: answer,
        value: index.toString(),
      }));

      const row = new MessageActionRow().addComponents(
        new MessageButton()
          .setCustomId('0')
          .setLabel(answers[0].label)
          .setStyle('PRIMARY'),
        new MessageButton()
          .setCustomId('1')
          .setLabel(answers[1].label)
          .setStyle('PRIMARY'),
        new MessageButton()
          .setCustomId('2')
        
setLabel(answers[2].label)
.setStyle('PRIMARY'),
new MessageButton()
.setCustomId('3')
.setLabel(answers[3].label)
.setStyle('PRIMARY')
);
          interaction.channel.send(question, { components: [row] });
};

sendQuestion();
}
});

client.login('YOUR_BOT_TOKEN');
Yazım hataları var. Fazla uzundu :D
!akinator kullanarak başlatıyorsun.
 

Geri
Yukarı