πBeispiele
Hier einfache API Beispiel:
discord.js:
const discord = require('discord.js');
const { Client, Intents } = discord;
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const fetch = require('node-fetch');
const botToken = "dein_token";
const botChannelId = 'deine_channel_id';
let lastProcessedVoteData = null;
async function fetchVotes() {
const response = await fetch("https://aeon-list.de/api/bot/deine_id/votes");
if (response.status === 200) {
const data = await response.json();
return data.votes;
} else {
return [];
}
}
client.on('ready', () => {
console.log("Bot ist bereit");
setInterval(checkVotesLoop, 60000);
});
async function checkVotesLoop() {
const votes = await fetchVotes();
if (votes.length > 0) {
const sortedVotes = votes.sort((a, b) => b.Date - a.Date);
for (const vote of sortedVotes) {
if (!lastProcessedVoteData || vote.Date > lastProcessedVoteData.Date) {
const user = client.users.cache.get(vote.user);
if (user) {
const channel = client.channels.cache.get(botChannelId);
channel.send(`Neue Bewertung von ${user}!`);
}
lastProcessedVoteData = vote;
}
}
}
}
client.login(botToken);```Discord.py
Last updated