Unexpected token '?' in Rest - discord.js

I'm trying to add slash commands to my discord bot using Discord.js and Rest but I keep getting an unexpected token somewhere in rest. Could anybody help me?
When I run:
const { SlashCommandBuilder, Routes } = require('discord.js');
const { REST } = require('#discordjs/rest');
var clientId = //myClientId
var guildId = //myGuildId
const commands = [
new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!')
]
commands.map(command => command.toJSON());
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
I Get:
/home/runner/TinkerTank/node_modules/#discordjs/rest/dist/lib/CDN.cjs:53
extension: extension ?? "png"
^
SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/runner/TinkerTank/node_modules/#discordjs/rest/dist/index.cjs:5:13)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
If somebody could help me out that would be great.

maby this will help you. npm install node#16.13.1 --save-dev --save-exact
For me, this solved the problem.
I found this here

Related

How can I solve a "fetch failed" when I reload a +page.svelte that depends on data from a +page.js

I get an fetch-failed error when I reload a +page.svelte (or load it via window.location.replace()) that depends on data from a +page.js.
In my current "solution" I use invalidate() in the onMount-function of the +error.svelte to load the data.
I'm looking for a better/correct approach to handle the loading.
error-message
fetch failed
TypeError: fetch failed
at Object.processResponse (C:xxx\node_modules\undici\lib\fetch\index.js:199:23)
at C:xxx\node_modules\undici\lib\fetch\index.js:928:38
at node:internal/process/task_queues:141:7
at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:138:8)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
+page.js
export const ssr = false; //1 module can't handle SSR
export const load = async ({ fetch }) => {
const response = await fetch(`https://localhost:5001/api/xxx`);
const obj= await response.json();
return {obj}
+error.svelte
onMount(async () => {
await invalidate();
});

TypeError: Cannot read properties of undefined (reading 'FLAGS') discord.js

so this is my bot code
const Discord = require("discord.js")
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES] });
client.on("ready", () => {
console.log('Logged in as ${client.user.tag}!')
console.log("Bot is online!")
})
client.on("message", msg => {
if (msg.content === "ping") {
msg.reply("no1se");
}
})
client.login("my token")
The error i get is this:
TypeError: Cannot read properties of undefined (reading 'FLAGS')
at Object.<anonymous> (/home/runner/no1seAlerts-1/index.js:4:47)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
Hint: hit control+c anytime to enter REPL.
(node:2004) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
yea so im trying to make a discor dbot everytime when i try to run it and make it online i get this error code i have no idea what to do and i would really appreciate any help thank you!
Assuming you are using discord.js v13, you can try and change your client to:
const client = new Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })
You should replace Intents with IntentsBitField
In your example it would be:
const client = new Client({ intents: [IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages] });
This was changed with version 14 of discord.js I believe.
Alternatively you can use GatewayIntentBits:
const client = new Client({ intents: [GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages] });
More information here
Hope this helps!

Error about Prisma in Remix's Jokes App tutorial

In Remix's Jokes App tutorial, I got an error in the process of getting a user in session.server.ts.
I think the error is about Prisma, but I don't know how to solve it.
url: https://remix.run/docs/en/v1/tutorials/jokes#authentication
TypeError: Cannot read properties of undefined (reading 'findUnique')
at login (/usr/src/app/remix-jokes/build/index.js:700:30)
at action2 (/usr/src/app/remix-jokes/build/index.js:751:26)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Object.callRouteAction (/usr/src/app/remix-jokes/node_modules/#remix-run/server-runtime/data.js:36:14)
at async renderDocumentRequest (/usr/src/app/remix-jokes/node_modules/#remix-run/server-runtime/server.js:216:24)
at async requestHandler (/usr/src/app/remix-jokes/node_modules/#remix-run/server-runtime/server.js:55:20)
at async /usr/src/app/remix-jokes/node_modules/#remix-run/express/server.js:45:22
It seems to occur in the findUnique call in the following code.
export async function login({
username,
password
}: LoginForm) {
const user = await db.user.findUnique({
where: { username }
});
if (!user) return null;
const isCorrectPassword = await bcrypt.compare(
password,
user.passwordHash
);
if (!isCorrectPassword) return null;
return user;
}
I restarted the Docker container and that solved the problem.
Thank you.

Discordjs TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client

I'm making a bot for ddiscord and I can't solve this error:
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const config = require('./config.json')
const dotenv = require('dotenv')
dotenv.config()
const privateMessage = require('./private-message');
const test = require('./test.js')
const mySecret = process.env['TOKEN'];
client.on('ready', () => {
console.log(`${client.user.tag} has logged in.`);
});
and this is the complete error:
D:\user\Bots\dadobot2801\a\node_modules\discord.js\src\client\Client.js:548
throw new TypeError('CLIENT_MISSING_INTENTS');
^
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (D:\user\Bots\dadobot2801\a\node_modules\discord.js\src\client\Client.js:548:13)
at new Client (D:\user\Bots\dadobot2801\a\node_modules\discord.js\src\client\Client.js:76:10)
at Object.<anonymous> (D:\user\Bots\dadobot2801\a\test.js:4:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (D:\user\Bots\dadobot2801\a\index.js:10:14) {
[Symbol(code)]: 'CLIENT_MISSING_INTENTS'
}
Any ideas?
Try using this. Since new updated of discord.js like version ^13.0 you have to specify client intents:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
Its how you do it
I had this problem before so i know how to fix it. You need to enable these 3 intents as seen in the image above.
Try this:
npm uni discord.js
npm i discord.js#12.5.3

Reference Plupload through middleware

I am trying to inject middle ware and load pl upload through that. Below are the packages I am trying to integrate inside my application.
https://www.npmjs.com/package/plupload
https://www.npmjs.com/package/redux-plupload
I am getting below error. I tried reinstall packages and run however no luck.
Need suggestion if I am missing anything.
ReferenceError: Image is not defined
at .....\node_modules\plupload\js\plupload.full.min.js:13:12305
at .....\node_modules\plupload\js\plupload.full.min.js:13:12504
at .....\node_modules\plupload\js\plupload.full.min.js:13:13299
at .....\node_modules\plupload\js\plupload.full.min.js:13:709
at i (.....\node_modules\plupload\js\plupload.full.min.js:13:402)
at n (.....\node_modules\plupload\js\plupload.full.min.js:13:687)
at .....\node_modules\plupload\js\plupload.full.min.js:13:5378
at Object.<anonymous> (.....\node_modules\plupload\js\plupload.full.min.js:16:11339)
at i (.....\node_modules\plupload\js\plupload.full.min.js:13:51)
at i (.....\node_modules\plupload\js\plupload.full.min.js:13:193)
at Object.<anonymous> (.....\node_modules\plupload\js\plupload.full.min.js:13:209)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Module._compile (.....\node_modules\pirates\lib\index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Object.newLoader [as .js] (.....\node_modules\pirates\lib\index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:600:32)
UPDATE -
Just to give more code insight, Below is the code
import {createMiddleware as createUploaderMiddleware} from 'redux-plupload';
import plupload from 'plupload';
const uploadDocmentMiddleware = (config) => (store) => (next) => (action) => {
// For now just returning some value
return true;
};
export default function configureStore(initialState) {
const uploaderMiddleware = createUploaderMiddleware(plupload, {
uploadDocmentMiddleware
});
return createStore(
rootReducer,
initialState,
// Initiate redux dev tools
composeWithDevTools(
applyMiddleware(
FirstMiddleware(config),
SecondMiddleware(config),
...
.....
// middle ware for pl upload
uploaderMiddleware(config),
typeof window !== 'undefined' && reduxImmutableStateInvariant()
)
)
);
}
Thank you!
We figured out, seems due to server rendering it breaks to load Pl upload and moxie.
We do not have any workaround yet for same. :(
Thanks though.

Resources