Comments (5)
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.
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.
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.
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.
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)
- TypeError: Cannot read property 'low' of undefined HOT 1
- bug: TSC reports 17 errors HOT 4
- bug: Focus isn't allowed in api.patch "/users/@me" HOT 1
- feat(ci): automatically bump revolt-api when applicable
- feat(ci): add automatic publish flow
- issue: importing revolt.js without skipLibCheck throws type errors HOT 2
- feat: add helper functions for generating preset attachment sizes
- bug: Error deleting a message after bot sends DM to user HOT 3
- bug: A simple CommonJS Bot, but: revolt-api/node_modules/axios: 404 error when someone joins server: http Request of members/00000000000000000000000000 HOT 3
- bug: If you restart revolt bot and someone leaves the server: serverMemberLeave event is not triggered. HOT 1
- bug: Can't install from git HOT 1
- bug: MessageReact event crashes with: TypeError: reactions.get is not a function HOT 1
- bug: update events don't use hydration key mappings
- bug: explicitly importing the ESM version fails
- feature request: add ability for client to delete emojis HOT 5
- bug: client.servers.fetch() not working due to missing permissions HOT 1
- feature request: Export Events Type
- bug: TextEmbed not working HOT 1
- TypeError: Cannot read properties of undefined (reading 'lastMessageId')
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from revolt.js.