Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: use ESM code in examples #9427

Merged
merged 3 commits into from
Apr 20, 2023
Merged

Conversation

MrMythicalYT
Copy link
Contributor

@MrMythicalYT MrMythicalYT commented Apr 19, 2023

Please describe the changes this PR makes and why it should be merged:
This PR converts the documentation examples from CommonJS to ESM.
Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • This PR only includes non-code changes, like changes to documentation, README, etc.

@vercel
Copy link

vercel bot commented Apr 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Apr 20, 2023 6:37am
discord-js-guide ⬜️ Ignored (Inspect) Apr 20, 2023 6:37am

@monbrey
Copy link
Member

monbrey commented Apr 19, 2023

Is this the only file that needs this change?

@Jiralite
Copy link
Member

Yeah, no other example uses require():

image

@almeidx
Copy link
Member

almeidx commented Apr 19, 2023

Can you update these too?

```js
const { REST, Routes } = require('discord.js');
const commands = [
{
name: 'ping',
description: 'Replies with Pong!',
},
];
const rest = new REST({ version: '10' }).setToken(TOKEN);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands });
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');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}
});
client.login(TOKEN);
```

@monbrey
Copy link
Member

monbrey commented Apr 19, 2023

Can you update these too?

```js
const { REST, Routes } = require('discord.js');
const commands = [
{
name: 'ping',
description: 'Replies with Pong!',
},
];
const rest = new REST({ version: '10' }).setToken(TOKEN);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands });
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');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}
});
client.login(TOKEN);
```

If you're updating that part of the README, it should probably align with my changes to the command deployment in the guide: https://github.com/discordjs/discord.js/pull/9385/files#diff-af7cad8eaebbb884ba861e35ce70fd37dcb6d78b8a491cd986356971b29fd4b9

Not the same level of detail, but use top-level-await, the Events enum instead of string events

@MrMythicalYT MrMythicalYT changed the title docs(Partials): use import statement docs: use ESM code in examples Apr 20, 2023
Copy link
Member

@kyranet kyranet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet TLA.

@kodiakhq kodiakhq bot merged commit ce287f2 into discordjs:main Apr 20, 2023
didinele pushed a commit that referenced this pull request Apr 21, 2023
* docs(Partials): use import statement

* docs: update readme to ESM

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants