SAMPForge

SAMPForge

SA:MP Resource Hub

Loading community resources...

Discord Webhooks & Integrasi Bot

Panduan menerima notifikasi otomatis ke server Discord dan contoh kode Bot Discord menggunakan discord.js.

Discord Webhooks

SAMPForge mengirimkan notifikasi Discord Embed otomatis setiap kali ada resource baru dipublikasikan atau versi baru dirilis.

Contoh Kode Bot Discord (discord.js)

Berikut contoh slash command /resource untuk mencari mod SA:MP langsung dari Discord:

JavaScript
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');

const API_BASE = 'https://sampforge.net/api/v1';

module.exports = {
  data: new SlashCommandBuilder()
    .setName('resource')
    .setDescription('Cari resource SA:MP di SAMPForge')
    .addStringOption(opt =>
      opt.setName('query').setDescription('Kata kunci').setRequired(true)
    ),

  async execute(interaction) {
    const query = interaction.options.getString('query');
    await interaction.deferReply();

    const res = await fetch(`${API_BASE}/resources?q=${encodeURIComponent(query)}&limit=5`);
    const { data } = await res.json();

    if (data.length === 0) {
      return interaction.editReply('Tidak ada resource ditemukan.');
    }

    const embeds = data.map(r =>
      new EmbedBuilder()
        .setTitle(r.name)
        .setURL(r.url)
        .setDescription(r.summary)
        .setThumbnail(r.thumbnail)
        .addFields(
          { name: 'Downloads', value: r.downloads.toLocaleString(), inline: true },
          { name: 'Author', value: r.author, inline: true },
          { name: 'Versi', value: r.latestVersion ?? '-', inline: true },
        )
        .setColor(0x00c896)
    );

    await interaction.editReply({ embeds: embeds.slice(0, 5) });
  },
};