Coder Social home page Coder Social logo

Comments (5)

BoQsc avatar BoQsc commented on July 20, 2024

As you can see in the example output

(node:454029) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'username' of undefined

username property is undefined.

from revolt.js.

BoQsc avatar BoQsc commented on July 20, 2024

Turns out to be very easy to reproduce.
I've tested this example with 4 bots and three separate servers, out of which one was completely new.
It happens to be that only the first invited bot is the only one capable of returning. guild_member.user.username and the whole guild_member.user object.

const { Client } = require("revolt.js");
let client = new Client();

console.info(`Welcome to a Basic Reaction Roles Bot.`);
console.info(`Revolt Library version: ${require("revolt.js").LIBRARY_VERSION}!`);
console.info(`_______________________________`);

let chat_message_reply;

client.on("message", async (message) => {
	
	if (message.content === "lets create reactions") {
		chat_message_reply = await message.channel.sendMessage("Select roles: ");
		try {
			console.log("Adding reactions to the message.");
			await chat_message_reply.react("01GK50B414WGS9M82668EZWMSX");
			await chat_message_reply.react("01GK50BBW5FP8PZSYTHYCJCG3W");
			await chat_message_reply.react("01GK50BH980WRKX5ATEETZMWZK");
			await chat_message_reply.react("01GK50BQA59VF31A04ERDTNPMG");
			await chat_message_reply.react("01GK50BYNR1PY1G479KCBA2QPR");
			console.log("Added reactions to the message sucessfully.");
		} catch (e) {
			if (e.response.status == 403){
				console.log(`An error response from the Revolt Server while trying to react to a message.`);
				console.log(`  ${e.response.status}: ${e.response.statusText}`);
				chat_message_reply.edit({
					content: `Bot has no **Use Reactions** permission in the  **${message.channel.server.name}** Guild.`

				});

				console.log(`    Please add "Use Reactions" permission to the Bot "${client.user.username}" in the Guild "${message.channel.server.name}". `);

			}
		}
		
	}
	
});

client.on("packet", async (event) => {
	if ((event.type == "MessageReact" || event.type == "MessageUnreact") && (event.user_id != client.user._id)){
		console.log("Red reaction.");
		
		client.servers.forEach(async (values, keys, objects) => {
			if (values.channel_ids.includes(event.channel_id) ){
				guild = await client.servers.get(values._id);
				guild_member = await guild.fetchMember(event.user_id);
		
				
				
				for (const [key, value] of Object.entries(guild_member)) {
								  console.log(`    ${key}: ${value}`);
				}
				
				console.log(`  Guild Name:  ${guild.name}`);
				
				console.log(`  Guild_Member Id: ${guild_member._id.user}`);
				console.log(`  Guild_Member Nickname: ${guild_member.nickname}`);
				console.log(`  Guild_Member Joined at: ${guild_member.joined_at}`);
				console.log(`  Guild_Member Roles: ${guild_member.roles}`);
				console.log(`  Guild_Member User: ${guild_member.user.username}`);
				console.log(`  Guild_Member User: ${guild_member.user}`);
					//console.log({ members: [guild_member]}); 
		
			/*
			console.log(await new Promise(function(){
				
					return	{ 
								members: [guild_member],
								users: ["happysuer"]
							
						};
			}
					));
					
					console.log("endreached");*/
				
				
			}
		});
		
		
		

		
	}
	
});

client.on("ready", async () => {
	client.users.edit({
		status: {
			text: "Listening to you.",
			presence: "Idle",
		},
	});
	
});

var fs = require('fs');
client.loginBot(fs.readFileSync('./token.txt','utf8'));

from revolt.js.

BoQsc avatar BoQsc commented on July 20, 2024

So yeah, this whole issue seems to be only about invited bots that are second or third or fourth... in the server.

from revolt.js.

BoQsc avatar BoQsc commented on July 20, 2024

Temporary untested workaround for other bot developers:
There is a chance that it is possible to do a workaround by fetching all members of the server/guild and selecting the user object.

https://revolt.js.org/classes/maps_Servers.Server.html#fetchMembers

Again, haven't tried that. Might not work as well.

from revolt.js.

insertish avatar insertish commented on July 20, 2024

The library is designed around the client so this is sort of intended behavior, users aren't fetched automatically with members. I am working towards figuring this out in the near future.

from revolt.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.