Why is guild.members.fetch timing out - javascript

Hello so I am writing a discord bot and all I want is an ordered list of members ordered by their ids. To achieve this I am running following code, however it just console.logs "Couldn't fetch members", with no further errors. :(
Upon further inspection, I discovered that it is a timeout error. Everything else works fine and I think that the const guild isn't the problem, but other than that hope that you people can help, Cheers!
const IDs = new Map();
var repeat = new Boolean(false);
var randomInt = new Number(0);
client.on('ready', () => {
console.log('Ready!');
const guild = client.guilds.cache.get("xxxxxxxxxxxxxxxxxx");
guild.members.fetch().then(members => {
console.log("Found the members");
IDs = members.map(user => user.id);
const OnlineMembers = members.filter(member => member.presence.status == "online");
}).catch(e => console.log("Couldn't fetch members."));
});
P.S. This is running on a Raspberry Pi over Nodemon --inspect, in case that changes anything

I found the solution, sorry if I bothered anybody, there is this really small setting in the Discord Dev Hub. That enables or disables this feature, obviously I was to dumb to turn it on from the start, thank you to anybody who took some time for this, Cheers!

Related

Unable to query or get any response from BscScan contract

The following code:
const { JsonRpcProvider } = require("#ethersproject/providers")
const { Contract } = require("ethers")
const { Wallet } = require("#ethersproject/wallet");
const abi = require('./abi.json');
const GLOBAL_CONFIG = {
PPV2_ADDRESS: "0x18B2A687610328590Bc8F2e5fEdDe3b582A49cdA",
PRIVATE_KEY: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
BSC_RPC: "https://bsc-mainnet.public.blastapi.io"
};
const signer = new Wallet(GLOBAL_CONFIG.PRIVATE_KEY, new JsonRpcProvider(GLOBAL_CONFIG.BSC_RPC));
const contract = new Contract(GLOBAL_CONFIG.PPV2_ADDRESS, abi, signer)
const predictionContract = contract.connect(
signer
)
predictionContract.on("StartRound", async (epoch) => {
console.log("\nStarted Epoch", epoch.toString())
});
It has been working perfectly for months. However, last night it stopped. No new builds/code changes on my end. I've been trying everything I can think of but nothing. The signer seems to bring back my wallet details ok. I can also see all the functions on the predictionContract but can't get it to return the current Epoch value etc. As you've probably already noticed, I'm not much of a coder, so any help in understanding this would be amazing.
After some more time thinking, I noticed that the contract seemed pretty busy and decided to try a different RPC (I'd already tried 3 before). Seems to be working now, but not exactly scientific. Is there any way to monitor the time requests take and where the lag is? I had a design idea to test a multiple of RPCs during initiation and then use the fastest / most reliable, but no idea where to start with that!

Discord.js messageReactionAdd Not firing

I understand that messageReactionAdd only works with cached messages but even after manually caching them it still wont fire.
Currently my code is:
client.once('ready', () => {
console.log(config.readymesssage);
var channel = client.channels.resolve('761577724379791450');
channel.messages.fetch({limit: 90}).then((message) => {
console.log("done")
})
});
client.on('messageReactionAdd', async(reaction) => {
console.log("reacted");
});
I have tried using raw events I used the code block from Here and I have also tried using partials, neither of which seem to be working. I'm unsure as to what else I cant try.
Enabling intents has fixed the issue, they first needed turning on in the developer portal and then I needed to add the following lines,
let Intss = new Discord.Intents(Discord.Intents.ALL);
const client = new Discord.Client({ws: { intents: Intss }});
Now the event is firing as expected.
Another working solution that is most likely better is
const bot = new Discord.Client({ partials: ['USER', 'REACTION', 'MESSAGE'] });
Now, you will have to check for partials before doing anything with the data (and fetch the data if it is partial). But this way, you won't have to deal with intents and if your bot scales to 100+ servers, you won't have to wait for verification either.

My Discord music bot stops songs 20 seconds before it is meant to

Now i'm not that good at Javascript, i consider myself still a learner as i still make quite a lot of mistakes from time to time (not without being able to fix them shortly after) but i am at a complete loss with this Discord bot that i'm coding, now i know that a decent amount is my code but this one area of my code i believe to possibly be the culprit of my discord bot cutting off the music stream around 20 seconds before the end.
function play(guild, song) {
const serverQueue = queue.get(guild.id);
if (!song) {
serverQueue.voiceChannel.leave();
return queue.delete(guild.id);
}
const dispatcher = serverQueue.connection.play(ytdl(song.url))
.on("end", () => {
const shiffed = serverQueue.songs.shift();
if (serverQueue.loop === true) {
serverQueue.songs.push(shiffed);
};
play(guild, serverQueue.songs[0]);
})
.on("error", error => console.error(error));
dispatcher.setVolume(serverQueue.volume / 100);
I am completely at a loss as i am not that good at Javascript i would really appreciate the help!
Edit:
Should mention i seen this post:
Discord bot audio end before the song end
they have the exact same issue as me and they said they were able to fix it but i am not able to do so and i would really appreciate if someone could give me a bit of help on this

connection.playStream is not a function

I know that there are a lot of question on this topic, but I browsed all of them but none of the answers seemed to fix my issue. I'm just creating a Discord bot for fun, I have almost never programmed in JavaScript but I wanted to try it.
My Code looks like this:
var url = "https://www.youtube.com/watch?v=HHv-s2OqYpw"
if(!message.member.voice.channel){
message.channel.send("Join a voice channel.");
return
} else {
vc = message.member.voice.channel;
connection = await vc.join();
isValid = ytdl.validateURL(url);
if(!isValid){
message.channel.send("The url you gave doesn't exist");
} else {
const stream = ytdl(url, {filter: "audioonly"});
const dispatcher = connection.playStream(stream)
dispatcher.on("end", function() {
vc.leave()
message.channel.send("Done playing the only music I can play lol")
})
I could do that it could play more songs but I only want it to play this one and in the terminal i get this error:
connection.playStream is not a function
I do have ytdl-core and opusscript installed and they both have the newest version. I tried doing this in lots of different ways, and it really annoys me that I can't figure out what the problem is. Sorry for bad english and thank those who help me. Have a nice day!
https://discord.js.org/#/docs/main/stable/class/VoiceConnection?scrollTo=play
As you can see, there's a VoiceConnection#play() method, and since you're most likely on v12, this is the method you're looking for.
const stream = ytdl(url, options);
const dispatcher = connection.play(stream);

Can't send embed message on join

No idea why it won't work, the exact code worked on my old bot. Code:
client.on("guildMemberAdd", member => {
const Discord = require("discord.js");
const embed = new Discord.RichEmbed()
.setTitle("**Please be sure to read our rules carefully thanks**")
.setAuthor("Welcome to BACKUP")
.setColor(3447003)
.setDescription("Please enjoy your stay")
.setThumbnail(message.author.avatarURL)
client.channels.get('505107608391254030').send({embed});
})
}
The thing that confuses me most, is that if I replace that code with this code, it works fine.
client.on('guildMemberAdd', member => {
member.guild.channels.get('505107608391254030').send("This works, but embed does not, fix it boi, line 102");
});
(On the code that did not work, I tried: client.channels.get, member.channels.get, member.guild.channels.get, client.guild.channels.get
The problem is when you are finding the channel, client.channels.get isn't a method. doesn't work in this situation for reasons I'm not aware of
You have to use client.guilds.get(GUILD_ID).channels.get(CHANNEL_ID).send({embed});

Categories

Resources