RoleUpdate Bug

I want to get the last updated role id, but it constantly prints the role id to the console .log. Is it normal to log this much?
No description
No description
46 Replies
d.js toolkit
d.js toolkit•10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
souji
souji•10mo ago
self-assignable roles (server guide etc.) are also emitted as roles updates also make sure you don't nest listeners within one another for example nesting this listener inside a messageCreate listener would attach a new roleUpdate listener for every message you receive and that can get out of hand quite quickly
mysterious3
mysterious3•10mo ago
i just want to get the id of the last updated role but it seems to loop when I do it this way. there is no other listener only rolupdate listener in my bot
souji
souji•10mo ago
put a log directly above the client.on and see if it gets attached multiple times
mysterious3
mysterious3•10mo ago
Can you write a sample code?
souji
souji•10mo ago
console.log("attaching roleUpdate listener");
client.on("roleUpdate", ...
console.log("attaching roleUpdate listener");
client.on("roleUpdate", ...
mysterious3
mysterious3•10mo ago
I'm trying now
No description
souji
souji•10mo ago
only outside the inner one would be execution, not attaching
mysterious3
mysterious3•10mo ago
No description
mysterious3
mysterious3•10mo ago
its ok ?
souji
souji•10mo ago
sure if you get that log more than once that explains everything
mysterious3
mysterious3•10mo ago
only wrote 1 message to the log
souji
souji•10mo ago
do more happen if you use the bot, assign/remove roles, etc.
mysterious3
mysterious3•10mo ago
attaching roleUpdate listener but we didn't include that log in the listener except that log will only be triggered when the bot starts.
souji
souji•10mo ago
if that is actually the case, that's good
mysterious3
mysterious3•10mo ago
i did everything it just wrote a message to the log once There is a problem with the roleupdate listener now I'm getting the code to write messages to that log inside the role update listener this for
mysterious3
mysterious3•10mo ago
No description
mysterious3
mysterious3•10mo ago
No description
mysterious3
mysterious3•10mo ago
when i change role permission it sends message like this
mysterious3
mysterious3•10mo ago
No description
souji
souji•10mo ago
you are changing one permission of one role and get this?
mysterious3
mysterious3•10mo ago
yes even when there is no loop i created a new bot just for this maybe there is a bug in this version When I update a role only once, it logs as much as the number of roles on the server.
souji
souji•10mo ago
you only change permission, not the role order? if you move the role, that'd make sense, since the position of the others will change as well
mysterious3
mysterious3•10mo ago
No, I just change the permission, for example, when I open the manage server permission to any role, it logs like this. it just goes into loop when i change role permission
souji
souji•10mo ago
i cannot reproduce that behaviour, if i change a permission i get a single roleUpdate event, as expected
mysterious3
mysterious3•10mo ago
If you want I can share my codes with you.
const { Client, GatewayIntentBits, Partials,AuditLogEvent } = require("discord.js")
const client = global.client = new Client({rest: { rejectOnRateLimit: false },fetchAllMembers:true,intents:Object.keys(GatewayIntentBits),partials:Object.keys(Partials)});
const DB = require('../../Shared/Databases/MongoDriver');
const Main = require('../../Shared/Services/Main');
const { ClientServices } = require('../../Shared/Services/Client');

ClientServices.sistemGereksinimleri();

client.login(System.Main.ShildIII).then(() => console.log(`🟢 ${client.user.username} Başarıyla Giriş Yaptı!`))
.catch((err) => console.log(`🔴 Bot Giriş Yapamadı / Sebep: ${err}`));

DB.Connect();
//Main.KomutYukle("Shield3");
//Main.EventYükle("Shield3");

ClientServices.BotVoiceJoin();
ClientServices.Activity();


client.on('roleUpdate', async (oldRole, newRole) => {
console.log("attaching roleUpdate listener");

return;
/*
try {
// Denetim kayıtlarını al
const auditLogs = await newRole.guild.fetchAuditLogs({
limit: 1,
type: AuditLogEvent.RoleUpdate
});
let int = 0;
// En son güncellenen rolün ID'sini al
const latestRoleUpdateLog = auditLogs.entries.first();
if (latestRoleUpdateLog) {
const roleId = latestRoleUpdateLog.target.id;
int += 1;
return console.log(`${int} En son güncellenen rol ID: ${roleId}`);

}
} catch (error) {
console.error("An error occurred:", error);
}
*/
});


require("../../Shared/Helpers/Prototype/Prototype");

process.on('unhandledRejection', (error) => {
console.error('Unhandled Promise Rejection:', error);
});
const { Client, GatewayIntentBits, Partials,AuditLogEvent } = require("discord.js")
const client = global.client = new Client({rest: { rejectOnRateLimit: false },fetchAllMembers:true,intents:Object.keys(GatewayIntentBits),partials:Object.keys(Partials)});
const DB = require('../../Shared/Databases/MongoDriver');
const Main = require('../../Shared/Services/Main');
const { ClientServices } = require('../../Shared/Services/Client');

ClientServices.sistemGereksinimleri();

client.login(System.Main.ShildIII).then(() => console.log(`🟢 ${client.user.username} Başarıyla Giriş Yaptı!`))
.catch((err) => console.log(`🔴 Bot Giriş Yapamadı / Sebep: ${err}`));

DB.Connect();
//Main.KomutYukle("Shield3");
//Main.EventYükle("Shield3");

ClientServices.BotVoiceJoin();
ClientServices.Activity();


client.on('roleUpdate', async (oldRole, newRole) => {
console.log("attaching roleUpdate listener");

return;
/*
try {
// Denetim kayıtlarını al
const auditLogs = await newRole.guild.fetchAuditLogs({
limit: 1,
type: AuditLogEvent.RoleUpdate
});
let int = 0;
// En son güncellenen rolün ID'sini al
const latestRoleUpdateLog = auditLogs.entries.first();
if (latestRoleUpdateLog) {
const roleId = latestRoleUpdateLog.target.id;
int += 1;
return console.log(`${int} En son güncellenen rol ID: ${roleId}`);

}
} catch (error) {
console.error("An error occurred:", error);
}
*/
});


require("../../Shared/Helpers/Prototype/Prototype");

process.on('unhandledRejection', (error) => {
console.error('Unhandled Promise Rejection:', error);
});
souji
souji•10mo ago
import { Client, version, GatewayIntentBits } from 'discord.js';

const client = new Client({
intents:
// GatewayIntentBits.DirectMessageReactions |
// GatewayIntentBits.DirectMessageTyping |
// GatewayIntentBits.DirectMessages |
GatewayIntentBits.GuildEmojisAndStickers |
GatewayIntentBits.GuildIntegrations |
GatewayIntentBits.GuildInvites |
GatewayIntentBits.GuildMembers |
GatewayIntentBits.GuildMessageReactions |
GatewayIntentBits.GuildMessageTyping |
GatewayIntentBits.GuildMessages |
GatewayIntentBits.GuildPresences |
GatewayIntentBits.GuildScheduledEvents |
GatewayIntentBits.GuildVoiceStates |
GatewayIntentBits.GuildWebhooks |
GatewayIntentBits.Guilds |
GatewayIntentBits.MessageContent,
});

client.on('ready', (client) => {
console.log(`Logged in on ${client.user.tag} (${client.user.id}) on version ${version}`);
});

client.on("roleUpdate", (oldRole, _newRole) => {
console.log(`roleupdate for ${oldRole}`)
})

await client.login(process.env.DISCORD_BOT_TOKEN);
import { Client, version, GatewayIntentBits } from 'discord.js';

const client = new Client({
intents:
// GatewayIntentBits.DirectMessageReactions |
// GatewayIntentBits.DirectMessageTyping |
// GatewayIntentBits.DirectMessages |
GatewayIntentBits.GuildEmojisAndStickers |
GatewayIntentBits.GuildIntegrations |
GatewayIntentBits.GuildInvites |
GatewayIntentBits.GuildMembers |
GatewayIntentBits.GuildMessageReactions |
GatewayIntentBits.GuildMessageTyping |
GatewayIntentBits.GuildMessages |
GatewayIntentBits.GuildPresences |
GatewayIntentBits.GuildScheduledEvents |
GatewayIntentBits.GuildVoiceStates |
GatewayIntentBits.GuildWebhooks |
GatewayIntentBits.Guilds |
GatewayIntentBits.MessageContent,
});

client.on('ready', (client) => {
console.log(`Logged in on ${client.user.tag} (${client.user.id}) on version ${version}`);
});

client.on("roleUpdate", (oldRole, _newRole) => {
console.log(`roleupdate for ${oldRole}`)
})

await client.login(process.env.DISCORD_BOT_TOKEN);
that's the minimal sample, works as expected (can ofc drop some intents, but this is my test instance with no code whatsoever)
mysterious3
mysterious3•10mo ago
What is the discord.js version?
souji
souji•10mo ago
14.13.0
mysterious3
mysterious3•10mo ago
now i will try with this code
souji
souji•10mo ago
issue with that is that it's integrated and uses quite a lot of things that i cannot just run here
mysterious3
mysterious3•10mo ago
No description
mysterious3
mysterious3•10mo ago
i created a new blank project i am trying now
mysterious3
mysterious3•10mo ago
No description
mysterious3
mysterious3•10mo ago
I tried your same codes
mysterious3
mysterious3•10mo ago
No description
souji
souji•10mo ago
you update various roles here those are all different ids maybe your server has a bot that does weird things
mysterious3
mysterious3•10mo ago
No description
souji
souji•10mo ago
well, then i have no idea
mysterious3
mysterious3•10mo ago
there is only bot and me, and when I update 1 role on the server, it logs like this, it's ridiculous, don't you have the same thing?
souji
souji•10mo ago
nope
mysterious3
mysterious3•10mo ago
okey
souji
souji•10mo ago
i mean, we can euqalize the comparison: https://discord.gg/ZStBC2Vj press the admin button and invite your bot
mysterious3
mysterious3•10mo ago
Thanks ı will trying I solved my mistake, the error was not in me or in the codes, the error was in the server, the server entered the bug, I put the same bot in a different server and it works without any errors.
souji
souji•10mo ago
hm, interesting
mysterious3
mysterious3•10mo ago
1 bot and 60 roles open test If you read the message from the beginning, you will understand what I have done. I was manually updating the server settings from the roles section with the manual discord application. Yes exactly I solved the problem, it was a problem with the server The server has entered a bug, for example, there are 2 roles named new roles, I cannot delete them. I'm writing a bot, I'm writing console.log('new attack') to the roleupdate event on my bot, when I update a role, it enters a manual loop so i don't actually loop it but it keeps throwing the log message as if it is looping when the role is due