I've set slash commands using client.application.commands.set, and that works fine, but I'm unsure how to add permissions for these commands. I've tried several answers on stackoverflow, but I believe v14 changed how to do this, but the docs haven't been updated and use separate libraries anyways.
Here's my code, simplified.
export default async function(client) {
let commands = [
{
name: `start`,
description: `start`,
},
{
name: `stop`,
description: `stop`,
},
]
await client.application.commands.set(commands, process.env.GUILD);
}
My end goal is a script that sets process.env.GUILD scoped slash commands that are whitelisted to be used by one role.
Try checking out the discord.js.org docs on it here :) It looks like you want to use the defaultMemberPermissions, which takes a PermissionResolvable, or integer bit field. You could do something like so:
const { PermissionFlagsBits } = require('discord-api-types/v10');
// Then you could access to bit flags like so:
console.log(PermissionFlagsBits.ManageChannels);
Related
The Backstage documentation states that all environment variables must be "exposed" through the central configuration file, app-config.yaml.
However, the official documentation is not clear about the use of these variables, for example, in the .ts and .tsx files.
Could someone help, or exemplify with codes how this use is made?
Had the same question, ended up just using process.env.ENV_VAR in the typescript files and exporting environment variables before starting Backstage.
There's a standard configuration API for both frontend and backend plugins or codes. An API reference can be found here.
You can try something like:
import { Config } from '#backstage/config';
interface IBackendConfig {
KEY_1: string;
KEY_2: string;
KEY_3: string;
}
const getBackendConfig = (config: Config): IBackendConfig => {
return config.get<IBackendConfig>('backend.env');
}
In your app-config.yaml
backend:
env:
KEY_1: "value1"
KEY_2: "value2"
KEY_3: "value3"
Note: Because of this syntax, configuration keys cannot contain dots.
Another option for accessing the env value is to create a sub-view of the configuration,
config.getConfig('backend').getString('env').
I am using the default formatting settings for React Native project. Prettier ("#react-native-community/eslint-config": "^2.0.0",). My if statements do not look good at least to me. I like to know if my if statements should be formatted as shown below or differently. Below is how prettier is formatting. Is there a better method. If so please post detailed information
const connect = async (addresses, port) => {
// check purchase information (entitlement)
try {
const purchaserInfo = await Purchases.getPurchaserInfo();
if (
typeof purchaserInfo.entitlements.active[DEFAULT_ENTITLEMENT_ID] !==
"undefined"
) {
// Grant user "pro" access
setNetwork(`http://${addresses[0]}:${port}`);
}
} catch (e) {
// Error fetching purchaser info
Bugfender.d('Purchases Error', e.message ); //prettier-ignore
}
};
It seems that your if condition is lengthy.
By default, Prettier’s printing algorithm prints expressions on a single line if they fit. It really helps readability if long single line converted to multi line. That's why long single line are automatically expanded.
Click here to read more
I am using Next.js and I am trying to redirect to a given path base on some regex conditions and cookie.
The goal is to redirect to /foo/bar when the source does not have the key bar and have a given cookie.
I have tried several different ways with next.config.js and none works.
Right now I have the following
async redirects() {
return [
{
source: '/(^(?:(?!bar).)*$)',
has: [{
type: 'cookie',
key: 'utm_source',
value: 'bar',
}],
destination: '/foo/bar',
permanent: true
}
]
}
The documentation is quite vague.
I also had a regex issue and was digging deep into next.js source code and did a little debugging. What I found is that unfortunately nobody tells you that next.js wraps your regex inside /^(?:\/( your regex ))$/i
Actually, the first part (\/) might depend on your source property.
But if you remove everything apart from the actual "word regex" it should work:
source: '/(?!bar)',
(Check out regexp.source in getPathMatch() in node_modules\next\dist\shared\lib\router\utils\path-match.js)
I've been working on creating discord bots using discord.js, and they've gotten large enough that I'd like to be able to set up automated testing for them - I've found this library (corde), but as it doesn't seem to be widely used, I'd like to see if there are other, more mature options available out there first.
Any help would be greatly appreciated. Manually testing bot commands one at a time is growing somewhat tiring.
If you read some of the examples in the github repo, you can simply set the prefix of all of your bots as the same (or change the code below) and then as the client logs in, it tests a command.
const { group, test, command, beforeStart, afterAll } = require("corde");
const { client, loginBot } = require("..");
beforeStart(() => {
loginBot();
});
group("main commands", () => {
test("Hello command should return... hello!!", () => {
expect("ping").shouldReturn("Ping?");
});
});
afterAll(() => {
client.destroy();
});
There is far more code that will help in the repo, here is the main index.js file if you need more assistance, or you could ask in a comment below.
I thought that allowing people to turn my blacklist on and off for their server would be kinda neat, but I didn't find much success so far. Also I was wondering, is it hard to make a command that allows people to add their own words to the blacklist? Here's the code:
let blacklisted = ['bad words here']
let foundInText = false;
for (var i in blacklisted) {
if (message.content.toLowerCase().includes(blacklisted[i].toLowerCase())) foundInText = true;
}
if (foundInText) {
message.delete();
}
});
You could use a variable for turning on or off the blacklist. BacklistOn = true, And use a if statement before the code you copied in here. Then make a command that changes that variable. You would need to store the variable in a JSON file if you want the setting to be saved when restarting the bot or if the bot crashes. Tutorial on reading/writing to JSON with node.js https://medium.com/#osiolabs/read-write-json-files-with-node-js-92d03cc82824