DiscordAPIError: Missing Access Discord V13 slash commands - discord

I keep getting this error:
C:\Users\faray\OneDrive\Documentos\GitHub\ShinsuBotHost\node_modules\discord.js\src\rest\RequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Access
at RequestHandler.execute (C:\Users\faray\OneDrive\Documentos\GitHub\ShinsuBotHost\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\faray\OneDrive\Documentos\GitHub\ShinsuBotHost\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async GuildApplicationCommandManager.set (C:\Users\faray\OneDrive\Documentos\GitHub\ShinsuBotHost\node_modules\discord.js\src\managers\ApplicationCommandManager.js:146:18)
at async C:\Users\faray\OneDrive\Documentos\GitHub\ShinsuBotHost\handlers\slash_handler.js:30:21 {
method: 'put',
path: '/applications/939213917958324234/guilds/932047617809068083/commands',
code: 50001,
httpStatus: 403,
requestData: {
json: [
{
name: 'hey',
description: undefined,
type: 3,
options: undefined,
default_permission: undefined
},
{
name: 'ping',
description: 'show ping',
type: undefined,
options: undefined,
default_permission: undefined
}
],
files: []
}
}
I've tried all the solutions proposed on the internet but none of them work. I've added all the permissions possible and the bot and applications.commands scopes to the bot. I am hosting my bot with Heroku.

Related

NextAuth safety of name in cookies field

I am currently using the following config in my NextAuth for production:
const options = {
secret: process.env.NEXTAUTH_SECRET,
adapter: PrismaAdapter(prisma),
providers: [...],
pages: {
signIn: '/signin'
},
callbacks: {
...,
cookies: {
sessionToken: {
name: 'next-auth.session-token',
options: {
httpOnly: true,
sameSite: 'lax',
path: '/',
secure: process.env.NODE_ENV === 'production',
domain: hostName
},
},
}
}
export default (req, res) => NextAuth(req, res, options)
However when looking back I was using:
name: process.env.NODE_ENV === 'production' ? `__Secure-next-auth.session-token` : 'next-auth.session-token'
The problem is that if I use the __Secure-next-auth.session-token the authentication does not work in production (the session is never created) what is the difference between using next-auth.session-token and __Secure-next-auth.session-token? does using next-auth.session-token in production make my application vulnerable?

Cannot log axios response from inside of a jest test

I am triggering a click event in a jest test using fireEvent which in turn triggers an axios request. I can see that the request is being made (or attempted, it returns the error message) but I get this message from jest saying it attempted to log the error (below). How can I get the error message to log properly when using axios with jest?
Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "error getting AxiosError {
message: 'Network Error',
name: 'AxiosError',
code: 'ERR_NETWORK',
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [Function: xhrAdapter],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function], Blob: [class Blob] },
validateStatus: [Function: validateStatus],
headers: AxiosHeaders { 'Content-Type': null, [Symbol(defaults)]: [Object] },
params: { specificURL: 'reviews/meta?product_id=37311' },
method: 'get',
url: 'http://localhost:3000/products',
data: undefined
},
request: XMLHttpRequest {}
}".
Here is my jest test:
import {render, fireEvent, screen, waitFor} from '#testing-library/react'
import React from 'react'
import ReactDOM from 'react-dom';
import RatingsAndReviews from '../RatingsAndReviews/RatingsAndReviews.js'
test('loads items eventually', async () => {
render(<RatingsAndReviews />)
const { container } = render(<RatingsAndReviews />);
const testButt = container.querySelector(`button[name="test-button"]`)
expect(testButt).toBeTruthy();
fireEvent.click(container.querySelector(`button[name="test-button"]`))
await waitFor(() => {
screen.findAllByText('Rating Test')
})

Storybook couldn't resolve fs

I am setting up a Storybook with RemixJS. I got the following error when trying to import a component
ERROR in ./node_modules/#remix-run/node/errors.js
Module not found: Error: Can't resolve 'fs' in '/Users/ht/Desktop/a/node_modules/#remix-run/node'
ERROR in ./node_modules/#remix-run/node/node_modules/source-map/lib/read-wasm.js
Module not found: Error: Can't resolve 'fs' in '/Users/ht/Desktop/a/node_modules/#remix-run/node/node_modules/source-map/lib'
ERROR in ./node_modules/#remix-run/node/sessions/fileStorage.js
Module not found: Error: Can't resolve 'fs' in '/Users/ht/Desktop/a/node_modules/#remix-run/node/sessions'
ERROR in ./node_modules/busboy/lib/main.js
Module not found: Error: Can't resolve 'fs' in '/Users/ht/Desktop/a/node_modules/busboy/lib'
ERROR in ./node_modules/#remix-run/node/errors.js
Module not found: Error: Can't resolve 'fs/promises' in '/Users/ht/Desktop/a/node_modules/#remix-run/node'
ERROR in ./node_modules/#remix-run/node/upload/fileUploadHandler.js 124:15
Module parse failed: Unexpected token (124:15)
You may need an appropriate loader to handle this file type, currently, no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| }
| class NodeOnDiskFile {
> lastModified = 0;
| webkitRelativePath = "";
|
ERROR in ./node_modules/#remix-run/node/formData.js 53:73
Module parse failed: Unexpected token (53:73)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| get(name) {
| let arr = this._fields[name];
> return (arr === null || arr === void 0 ? void 0 : arr.slice(-1)[0]) ?? null;
| }
|
I got the suggestion that I should add this to the web pack
{
resolve: {
fallback: {
fs: false
}
}
}
How could I do it with a storybook? I use storybook version 6.4.19
I added this to .storybook/main.js but without success
webpackFinal: async (config, { configType }) => {
config.node = {
...config.node,
fs: 'empty'
};
return config;
},
Thank you
Depending on the webpack version you are using to build your Storybook you need to add fs, stream and other Node core module used by Remix packages.
As a rule of thumb you can use the list from Webpack documentation on resolve.fallback here.
If you are using Stroybook with Webpack 4 the config should look like :
module.exports = {
// Storybook config
webpackFinal: async (config, { configType }) => {
config.node = {
...config.node,
fs: "empty",
assert: "empty",
buffer: "empty",
console: "empty",
constants: "empty",
crypto: "empty",
domain: "empty",
events: "empty",
http: "empty",
https: "empty",
os: "empty",
path: "empty",
punycode: "empty",
process: "empty",
querystring: "empty",
stream: "empty",
string_decoder: "empty",
sys: "empty",
timers: "empty",
tty: "empty",
url: "empty",
util: "empty",
vm: "empty",
zlib: "empty",
};
return config;
},
};
Or with Webpack 5
module.exports = {
// Storybook config
webpackFinal: async (config, { configType }) => {
config.resolve.fallback = {
fs: false,
assert: false,
buffer: false,
console: false,
constants: false,
crypto: false,
domain: false,
events: false,
http: false,
https: false,
os: false,
path: false,
punycode: false,
process: false,
querystring: false,
stream: false,
string_decoder: false,
sys: false,
timers: false,
tty: false,
url: false,
util: false,
vm: false,
zlib: false,
};
return config;
},
};
Upgrade storybook to use webpack 5
https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324
Update .storybook/main.js
module.exports = {
stories: ["../.slicemachine/assets/**/*.stories.#(js|jsx|ts|tsx)"],
addons: [
"#storybook/addon-links",
"#storybook/addon-essentials",
"#storybook/addon-interactions",
],
framework: "#storybook/react",
core: {
builder: "webpack5",
},
webpackFinal: async (config, { configType }) => {
config.resolve = {
...config.resolve,
fallback: {
...(config.resolve || {}).fallback,
fs: false,
stream: false,
os: false,
},
}
// Return the altered config
return config
},
}

Next.js redirect if there is no cookie

Is there a way to redirect the user from checkout to the join page ONLY if there is no cookie user_token. Next.js allows to set only strings and undefined as value, but I need to validate that there is no cookie:
redirects: async () => [
{
source: '/checkout',
has: [
{
type: 'cookie',
key: 'user_token',
value: '',
},
],
permanent: true,
destination: '/join',
},
],
I tried to use regex for empty string, but it did not work:
redirects: async () => [
{
source: '/checkout',
has: [
{
type: 'cookie',
key: 'user_token',
value: '(^$)',
},
],
permanent: true,
destination: '/join',
},
],
I think that the problem you have is, that you just limit it to an empty cookie.
You will have to check for the absence of a cookie inside the route and send a res.redirect from there (https://nextjs.org/docs/api-routes/response-helpers)
And: are you sure you want a permanent redirect?? The browser caches it and those users will be redirected without a request to the server in the future.

eslint Parsing error: Unexpected token up in migration.js

in my previous project i used this syntax for migration to mongoDB:
my_migration.js //
'use strict';
import slug from 'slugify';
module.exports = {
async up(db) {
const categories = [
{
title: 'football',
slug: slug('football'),
createdAt: new Date().getTime(),
updatedAt: new Date().getTime()
},
];
await db.collection('categories').insertMany(categories);
}
};
And it works, but an another project(Nextjs, Reactjs, Nodejs) I have eslint error:
[eslint] Parsing error: Unexpected token up
(method) up(db: any): Promise<void>
What I am doing incorrect? Thanks for any help.
eslintrc.js/
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"ecmaVersion": 2017,
"sourceType": "module"
},

Resources