mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
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:
59
packages/discord.js/test/monetization.js
Normal file
59
packages/discord.js/test/monetization.js
Normal 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);
|
||||
Reference in New Issue
Block a user