Hi so i am making a discord.js command handler package and set this.prefix in the main file when a new class is invoked so how would i use this.prefix in a secondary file's function rather than passing the prefix as an argument.
const { Client } = require('discord.js')
const {load} = require('cmd-handler/load-commands')
const Discord = require('discord.js')
class newhandler {
constructor(client, commandpath, eventpath, {prefix}){
this.commandpath = commandpath
this.prefix = prefix
this.client = client
client.cmds = new Discord.Collection()
client.aliases = new Discord.Collection()
load(this.commandpath, client)
client.on('message', (msg) => {
const {msgev} = require('./events/message')
msgev(msg)
})
}
}
module.exports.newhandler = newhandler
const msgev = async(message) => {
console.log(this.prefix)
if(!message.content.startsWith(this.prefix)) return
if(!message.guild) return
if(message.author.bot) return
const args = message.content.slice(prefix.length).trim().split(/ + /g)
const cmd = args.shift().toLowerCase()
const command = this.client.cmds.get(cmd) || this.client.aliases.get(cmd)
console.log(command)
if(command) {
command.run(client, message, args)
}
}
module.exports.msgev = msgev
question from:
https://stackoverflow.com/questions/65860198/how-to-use-this-values-in-another-files-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…