mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
refactor: use optional chaining (#6757)
This commit is contained in:
@@ -48,7 +48,7 @@ class APIRequest {
|
|||||||
if (this.options.headers) headers = Object.assign(headers, this.options.headers);
|
if (this.options.headers) headers = Object.assign(headers, this.options.headers);
|
||||||
|
|
||||||
let body;
|
let body;
|
||||||
if (this.options.files && this.options.files.length) {
|
if (this.options.files?.length) {
|
||||||
body = new FormData();
|
body = new FormData();
|
||||||
for (const file of this.options.files) {
|
for (const file of this.options.files) {
|
||||||
if (file?.file) body.append(file.key ?? file.name, file.file, file.name);
|
if (file?.file) body.append(file.key ?? file.name, file.file, file.name);
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ class RequestHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sublimitTimeout;
|
let sublimitTimeout;
|
||||||
if (res && res.headers) {
|
if (res.headers) {
|
||||||
const serverDate = res.headers.get('date');
|
const serverDate = res.headers.get('date');
|
||||||
const limit = res.headers.get('x-ratelimit-limit');
|
const limit = res.headers.get('x-ratelimit-limit');
|
||||||
const remaining = res.headers.get('x-ratelimit-remaining');
|
const remaining = res.headers.get('x-ratelimit-remaining');
|
||||||
|
|||||||
@@ -926,7 +926,7 @@ class Guild extends AnonymousGuild {
|
|||||||
const welcome_channels = welcomeChannels?.map(welcomeChannelData => {
|
const welcome_channels = welcomeChannels?.map(welcomeChannelData => {
|
||||||
const emoji = this.emojis.resolve(welcomeChannelData.emoji);
|
const emoji = this.emojis.resolve(welcomeChannelData.emoji);
|
||||||
return {
|
return {
|
||||||
emoji_id: emoji && emoji.id,
|
emoji_id: emoji?.id,
|
||||||
emoji_name: emoji?.name ?? welcomeChannelData.emoji,
|
emoji_name: emoji?.name ?? welcomeChannelData.emoji,
|
||||||
channel_id: this.channels.resolveId(welcomeChannelData.channel),
|
channel_id: this.channels.resolveId(welcomeChannelData.channel),
|
||||||
description: welcomeChannelData.description,
|
description: welcomeChannelData.description,
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ const tests = [
|
|||||||
client.on('messageCreate', async message => {
|
client.on('messageCreate', async message => {
|
||||||
if (message.author.id !== owner) return;
|
if (message.author.id !== owner) return;
|
||||||
const match = message.content.match(/^do (.+)$/);
|
const match = message.content.match(/^do (.+)$/);
|
||||||
if (match && match[1] === 'it') {
|
if (match?.[1] === 'it') {
|
||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
for (const [i, test] of tests.entries()) {
|
for (const [i, test] of tests.entries()) {
|
||||||
await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``);
|
await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``);
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ client.on('messageCreate', async message => {
|
|||||||
{ type: 'TextChannel#fetchWebhooks', hook: await message.channel.fetchWebhooks().then(x => x.first()) },
|
{ type: 'TextChannel#fetchWebhooks', hook: await message.channel.fetchWebhooks().then(x => x.first()) },
|
||||||
{ type: 'Guild#fetchWebhooks', hook: await message.guild.fetchWebhooks().then(x => x.first()) },
|
{ type: 'Guild#fetchWebhooks', hook: await message.guild.fetchWebhooks().then(x => x.first()) },
|
||||||
];
|
];
|
||||||
if (match && match[1] === 'it') {
|
if (match?.[1] === 'it') {
|
||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
for (const { type, hook } of hooks) {
|
for (const { type, hook } of hooks) {
|
||||||
for (const [i, test] of tests.entries()) {
|
for (const [i, test] of tests.entries()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user