From ce287f21d1540da7f17cac8a57dc33a67f391ef3 Mon Sep 17 00:00:00 2001 From: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com> Date: Thu, 20 Apr 2023 02:40:15 -0400 Subject: [PATCH] docs: use ESM code in examples (#9427) * docs(Partials): use import statement * docs: update readme to ESM --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/discord.js/README.md | 20 +++++++++----------- packages/discord.js/src/util/Partials.js | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/discord.js/README.md b/packages/discord.js/README.md index 18ce3adf3..885440ff9 100644 --- a/packages/discord.js/README.md +++ b/packages/discord.js/README.md @@ -57,7 +57,7 @@ pnpm add discord.js Register a slash command against the Discord API: ```js -const { REST, Routes } = require('discord.js'); +import { REST, Routes } from 'discord.js'; const commands = [ { @@ -68,23 +68,21 @@ const commands = [ const rest = new REST({ version: '10' }).setToken(TOKEN); -(async () => { - try { - console.log('Started refreshing application (/) commands.'); +try { + console.log('Started refreshing application (/) commands.'); - await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands }); + await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands }); - console.log('Successfully reloaded application (/) commands.'); - } catch (error) { - console.error(error); - } -})(); + console.log('Successfully reloaded application (/) commands.'); +} catch (error) { + console.error(error); +} ``` Afterwards we can create a quite simple example bot: ```js -const { Client, GatewayIntentBits } = require('discord.js'); +import { Client, GatewayIntentBits } from 'discord.js'; const client = new Client({ intents: [GatewayIntentBits.Guilds] }); client.on('ready', () => { diff --git a/packages/discord.js/src/util/Partials.js b/packages/discord.js/src/util/Partials.js index 3a73c9bee..31d92231c 100644 --- a/packages/discord.js/src/util/Partials.js +++ b/packages/discord.js/src/util/Partials.js @@ -5,7 +5,7 @@ const { createEnum } = require('./Enums'); /** * The enumeration for partials. * ```js - * const { Client, Partials } = require('discord.js'); + * import { Client, Partials } from 'discord.js'; * * const client = new Client({ * intents: [