Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
How do I create server specific variables in Discord.js?

I made a slash command that uses a channel selection. I'm using this to set the logging channel. I need help to have the same variable but with different values per-server.

For example:

Server 1 = #logs

Server 2 = #mod-only

I don't know how to get variables to have different values in different servers.

Right now I have this. but if you ban someone in "Server 2", it will log to "Server 1."

logchannel.js

var logchannel = interaction.options.getChannel('channel');
        exports.logchannel = logchannel;

ban.js

var logchannel = require('./logchannel');
        var logchannel = logchannel.logchannel;
        logchannel.send('message');

I need to figure out how to get the log channel variable to have different values throughout different servers. If anyone could answer how to do this please let me know.

I also already tried using MongoDB and it did not work for me.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here's one solution without using mongo but you can achieve the same with mongo. There are many approaches you can take to achieve the same it's a basic one and not the best.

const logChannels = {
        'serverID': 'channelID',
        'anotherserverID': 'anotherchannelID',
}
var logchannel = logChannels[guild.id] // Here you will have your log channel ID
guild.channels.cache.get(logchannel).send(`message`)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!