Skip to content

Instantly share code, notes, and snippets.

@Corex24
Last active September 24, 2025 16:56
Show Gist options
  • Select an option

  • Save Corex24/056f8cedf32a07fd960be63b22be14b1 to your computer and use it in GitHub Desktop.

Select an option

Save Corex24/056f8cedf32a07fd960be63b22be14b1 to your computer and use it in GitHub Desktop.
Plugin for livescoreπŸ’™βš½οΈπŸŸπŸ“πŸ§€
// Plugin by Corex πŸ’™
const { bot } = require('../lib/');
const fetch = (...args) =>
import('node-fetch').then(({ default: fetch }) => fetch(...args));
const API_KEY = '52d192da6e86b2e9121f15079b879c57';
bot(
{
pattern: 'livescore',
desc: 'Get live football scores (or today\'s fixtures if none live)',
type: 'sports',
},
async (message, match) => {
try {
// 1. Fetch live matches first
let res = await fetch('https://v3.football.api-sports.io/fixtures?live=all', {
method: 'GET',
headers: {
'x-apisports-key': API_KEY,
},
});
let json = await res.json();
let matches = json.response;
// 2. If no live matches, fallback to today’s fixtures
if (!matches || !matches.length) {
const today = new Date().toISOString().split('T')[0];
res = await fetch(`https://v3.football.api-sports.io/fixtures?date=${today}`, {
method: 'GET',
headers: {
'x-apisports-key': API_KEY,
},
});
json = await res.json();
matches = json.response;
if (!matches || !matches.length) {
return await message.send('⚽ No matches found for today.');
}
}
// 3. Build fancy reply
let replyText = `╔══════════════ ⚽ π—Ÿπ—œπ—©π—˜π—¦π—–π—’π—₯π—˜ ⚽ ═════════════╗\n\n`;
for (let match of matches.slice(0, 8)) {
const home = match.teams.home.name;
const away = match.teams.away.name;
const homeGoals = match.goals.home ?? 0;
const awayGoals = match.goals.away ?? 0;
const status = match.fixture.status.long;
const league = match.league.name;
const time = new Date(match.fixture.date).toLocaleTimeString('en-GB', {
hour: '2-digit',
minute: '2-digit',
});
replyText += `πŸ† *${league}*\n`;
replyText += `⚑ ${home} ${homeGoals} - ${awayGoals} ${away}\n`;
replyText += `⏰ ${time} | πŸ“ ${status}\n\n`;
}
replyText += `═══════════════════════════════════════\n`;
replyText += `πŸ‘¨β€πŸ’» Created by *Corex* with πŸ’™\n`;
replyText += `═══════════════════════════════════════`;
await message.send(replyText.trim());
} catch (err) {
console.error(err);
await message.send('❌ Could not fetch football scores. Please try again later.');
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment