在 discord.js 上制作 .env 文件和修改代码
Making .env file and modifty codes on discord.js
谁能帮我创建 .env 文件并修改代码!
这是 discord.js v12
我不能修改此代码上的 .env 代码!
但它没有用
请在这个系统中帮助我!而且是纱线安装法!
js 文件 => RushGamerzClient.js
const { Client } = require('discord.js');
module.exports = class RushGamerzClient extends Client {
constructor(options = {}) {
super({
disableMentions: 'everyone'
});
this.validate(options);
this.once('ready', () => {
console.log(`Logged in as ${this.user.username}!`);
});
this.on('message', async (message) => {
const mentionRegex = RegExp(`^<@!${this.user.id}>$`);
const mentionRegexPrefix = RegExp(`^<@!${this.user.id}> `);
if (!message.guild || message.author.bot) return;
if (message.content.match(mentionRegex)) message.channel.send(`My prefix for ${message.guild.name} is \`${this.prefix}\`.`);
const prefix = message.content.match(mentionRegexPrefix) ?
message.content.match(mentionRegexPrefix)[0] : this.prefix;
if (!message.content.startsWith(prefix)) return;
// eslint-disable-next-line no-unused-vars
const [cmd, ...args] = message.content.slice(prefix.length).trim().split(/ +/g);
if (cmd.toLowerCase() === 'hello') {
message.channel.send('Hello!');
}
});
}
validate(options) {
if (typeof options !== 'object') throw new TypeError('Options should be a type of Object.');
if (!options.token) throw new Error('You must pass the token for the client.');
this.token = options.token;
if (!options.prefix) throw new Error('You must pass a prefix for the client.');
if (typeof options.prefix !== 'string') throw new TypeError('Prefix should be a type of String.');
this.prefix = options.prefix;
}
async login(token = this.token) {
super.login(token);
}
};
js 文件 => index.js 代码在这里
const RushGamerzClient = require('./Structures/RushGamerzClient');
const config = require('../config.json');
const client = new RushGamerzClient(config);
client.login();
解决问题的选项很少:
使用具有
DISCORD_TOKEN="<your-token>"
然后在文件顶部使用 dotenv
(使用 npm i -G dotenv
安装),并使用环境变量
登录
require('dotenv').config();
...
client.login(process.env.DISCORD_TOKEN);
谁能帮我创建 .env 文件并修改代码! 这是 discord.js v12 我不能修改此代码上的 .env 代码! 但它没有用 请在这个系统中帮助我!而且是纱线安装法!
js 文件 => RushGamerzClient.js
const { Client } = require('discord.js');
module.exports = class RushGamerzClient extends Client {
constructor(options = {}) {
super({
disableMentions: 'everyone'
});
this.validate(options);
this.once('ready', () => {
console.log(`Logged in as ${this.user.username}!`);
});
this.on('message', async (message) => {
const mentionRegex = RegExp(`^<@!${this.user.id}>$`);
const mentionRegexPrefix = RegExp(`^<@!${this.user.id}> `);
if (!message.guild || message.author.bot) return;
if (message.content.match(mentionRegex)) message.channel.send(`My prefix for ${message.guild.name} is \`${this.prefix}\`.`);
const prefix = message.content.match(mentionRegexPrefix) ?
message.content.match(mentionRegexPrefix)[0] : this.prefix;
if (!message.content.startsWith(prefix)) return;
// eslint-disable-next-line no-unused-vars
const [cmd, ...args] = message.content.slice(prefix.length).trim().split(/ +/g);
if (cmd.toLowerCase() === 'hello') {
message.channel.send('Hello!');
}
});
}
validate(options) {
if (typeof options !== 'object') throw new TypeError('Options should be a type of Object.');
if (!options.token) throw new Error('You must pass the token for the client.');
this.token = options.token;
if (!options.prefix) throw new Error('You must pass a prefix for the client.');
if (typeof options.prefix !== 'string') throw new TypeError('Prefix should be a type of String.');
this.prefix = options.prefix;
}
async login(token = this.token) {
super.login(token);
}
};
js 文件 => index.js 代码在这里
const RushGamerzClient = require('./Structures/RushGamerzClient');
const config = require('../config.json');
const client = new RushGamerzClient(config);
client.login();
解决问题的选项很少:
使用具有
DISCORD_TOKEN="<your-token>"
然后在文件顶部使用 dotenv
(使用 npm i -G dotenv
安装),并使用环境变量
require('dotenv').config();
...
client.login(process.env.DISCORD_TOKEN);