feat: premium application subscriptions (#9907)

* feat: premium application subscriptions

* types: readonly array

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* fix: requested changes

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* fix: core client types

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Almeida
2023-12-24 15:49:58 +00:00
committed by GitHub
parent 520d6f64dd
commit c4fcee3ef6
33 changed files with 914 additions and 10 deletions

View File

@@ -0,0 +1,59 @@
'use strict';
const { token, owner } = require('./auth.js');
const { Client, Events, codeBlock, GatewayIntentBits } = require('../src');
const client = new Client({ intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildMessages });
client.on('raw', console.log);
client.on(Events.ClientReady, async () => {
const commands = await client.application.commands.fetch();
if (!commands.size) {
await client.application.commands.set([
{
name: 'test',
description: 'yeet',
},
]);
}
const skus = await client.application.fetchSKUs();
console.log('skus', skus);
const entitlements = await client.application.entitlements.fetch();
console.log('entitlements', entitlements);
});
client.on(Events.EntitlementCreate, entitlement => console.log('EntitlementCreate', entitlement));
client.on(Events.EntitlementDelete, entitlement => console.log('EntitlementDelete', entitlement));
client.on(Events.EntitlementUpdate, (oldEntitlement, newEntitlement) =>
console.log('EntitlementUpdate', oldEntitlement, newEntitlement),
);
client.on(Events.InteractionCreate, async interaction => {
console.log('interaction.entitlements', interaction.entitlements);
if (interaction.commandName === 'test') {
await interaction.sendPremiumRequired();
}
});
client.on(Events.MessageCreate, async message => {
const prefix = `<@${client.user.id}> `;
if (message.author.id !== owner || !message.content.startsWith(prefix)) return;
let res;
try {
res = await eval(message.content.slice(prefix.length));
if (typeof res !== 'string') res = require('node:util').inspect(res);
} catch (err) {
// eslint-disable-next-line no-console
console.error(err.stack);
res = err.message;
}
await message.channel.send(codeBlock('js', res));
});
client.login(token);