remove and add roles stop after time of running ?

hi guy's i want to ask about this problem My bot works on my server to organize the server in general, remove roles, give them and take them away, and arrange the levels within my server. But in the past period The system has become unresponsive to many commands Such as add and remove roles (especially in this regard) As it caused many problems within my server My code works normally when tested on my test bot But when activated in the main bot, the system stops to respone for this handles (give and remove roles) after a while I use a library discord.js Is the problem with the library or is there another defect?
4 Replies
d.js toolkit
d.js toolkit9mo 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!
Radis Easton
Radis EastonOP9mo ago
hi @Qjuh thank you for reply . on code it's normal command to add roles it's work nomrmaly but i have alot of my other reaction handler like when some on join server using emoji and get roles and like that things> can you tall me more about ratelimit , i think my system do a lot of roles handling (add - remove)
ShompiFlen
ShompiFlen9mo ago
please show us your code instead of describing it upload the relevant piece of code to pastebin / hastebin and send it here so we can take a look
Radis Easton
Radis EastonOP9mo ago
luna is the Client and this functions on my class it's work , but after a while the system don't give roles or remove them.
GiveRole(GuildID, PlayerID, RoleID) {
const Guild = this.luna.guilds.cache.get(GuildID);
if(Guild){


const Member = Guild.members.cache.find(member => member.id == PlayerID)
if (!Member) return console.log(`[ERROR GiveRole][@Function] #i can't find the @Member with (ID = ${PlayerID}) in @Guild (ID = ${GuildID})`);
const Role = Guild.roles.cache.find(role => role.id == RoleID)
if (!Role) return console.log(`[ERROR GiveRole][@Function] #i can't find the @Role with (ID = ${RoleID}) in @Guild (ID = ${GuildID})`);

Member.roles.add(Role).catch(error => {
console.error(`[ERROR GiveRole][@Function] #i can't Add the @Role with (ID = ${RoleID}) to @Member with (ID = ${PlayerID}) in @Guild (ID = ${GuildID})`)
});
}
}




RemoveRole(GuildID, PlayerID, RoleID) {
const Guild = this.luna.guilds.cache.get(GuildID);
if(Guild){

const Member = Guild.members.cache.find(member => member.id == PlayerID)
if (!Member) return console.log(`[ERROR RemoveRole][@Function] #i can't find the @Member with (ID = ${PlayerID}) in @Guild (ID = ${GuildID})`);
const Role = Guild.roles.cache.find(role => role.id == RoleID)
if (!Role) return console.log(`[ERROR RemoveRole][@Function] #i can't find the @Role with (ID = ${RoleID}) in @Guild (ID = ${GuildID})`);

Member.roles.remove(Role).catch(error => {
console.error(`[ERROR RemoveRole][@Function] #i can't Remove the @Role with (ID = ${RoleID}) to @Member with (ID = ${PlayerID}) in @Guild (ID = ${GuildID})`)
});

}
}
GiveRole(GuildID, PlayerID, RoleID) {
const Guild = this.luna.guilds.cache.get(GuildID);
if(Guild){


const Member = Guild.members.cache.find(member => member.id == PlayerID)
if (!Member) return console.log(`[ERROR GiveRole][@Function] #i can't find the @Member with (ID = ${PlayerID}) in @Guild (ID = ${GuildID})`);
const Role = Guild.roles.cache.find(role => role.id == RoleID)
if (!Role) return console.log(`[ERROR GiveRole][@Function] #i can't find the @Role with (ID = ${RoleID}) in @Guild (ID = ${GuildID})`);

Member.roles.add(Role).catch(error => {
console.error(`[ERROR GiveRole][@Function] #i can't Add the @Role with (ID = ${RoleID}) to @Member with (ID = ${PlayerID}) in @Guild (ID = ${GuildID})`)
});
}
}




RemoveRole(GuildID, PlayerID, RoleID) {
const Guild = this.luna.guilds.cache.get(GuildID);
if(Guild){

const Member = Guild.members.cache.find(member => member.id == PlayerID)
if (!Member) return console.log(`[ERROR RemoveRole][@Function] #i can't find the @Member with (ID = ${PlayerID}) in @Guild (ID = ${GuildID})`);
const Role = Guild.roles.cache.find(role => role.id == RoleID)
if (!Role) return console.log(`[ERROR RemoveRole][@Function] #i can't find the @Role with (ID = ${RoleID}) in @Guild (ID = ${GuildID})`);

Member.roles.remove(Role).catch(error => {
console.error(`[ERROR RemoveRole][@Function] #i can't Remove the @Role with (ID = ${RoleID}) to @Member with (ID = ${PlayerID}) in @Guild (ID = ${GuildID})`)
});

}
}
on normal i do that wait i show you one of my codes
execute(message, args, luna, Discord, prefix, index, useridfromslash, guildid, slashcommandon) {


mongoose.connect(mongoPass, {
useNewUrlParser: true,
useUnifiedTopology: true,
})

const ChannelSlash = luna.channels.cache.find(channel => channel.id === message)
const PlayerSystemFunctions = new MyPlayerSystemFunctions(luna);

const ChallengeCoin = luna.emojis.cache.find(emoji => emoji.name === "ChallengeCoin");
var LunaMsg = new MessageExtra(ChannelSlash ,message , useridfromslash , slashcommandon, luna)


var AcceptedRoles = new ArrayList;

AcceptedRoles.add(["1157940292469674004","937314384009654323","885599560402092043" ,"885604872215466045","950735462518124634" , "940231757922439179"]);



var role = args[0];
role = role.replace("<@&","");
role = role.replace(">","");

if(!AcceptedRoles.contains(role))
return LunaMsg.send("**لا يمكن إعطاء هذه الرتبة**", "@");

args = args.filter(item => item !== args[0])

args.forEach(async user => {
user = user.replace("<", "");
user = user.replace("@", "");
user = user.replace(">", "");
user = user.replace("!", "");

if (parseInt(user) != `NaN`) {
await PlayerSystemFunctions.GiveRole(guildid,user,role)
}
});

LunaMsg.send(`**تم توزيع بنجاح <@&${role}>**`,"@")
}
execute(message, args, luna, Discord, prefix, index, useridfromslash, guildid, slashcommandon) {


mongoose.connect(mongoPass, {
useNewUrlParser: true,
useUnifiedTopology: true,
})

const ChannelSlash = luna.channels.cache.find(channel => channel.id === message)
const PlayerSystemFunctions = new MyPlayerSystemFunctions(luna);

const ChallengeCoin = luna.emojis.cache.find(emoji => emoji.name === "ChallengeCoin");
var LunaMsg = new MessageExtra(ChannelSlash ,message , useridfromslash , slashcommandon, luna)


var AcceptedRoles = new ArrayList;

AcceptedRoles.add(["1157940292469674004","937314384009654323","885599560402092043" ,"885604872215466045","950735462518124634" , "940231757922439179"]);



var role = args[0];
role = role.replace("<@&","");
role = role.replace(">","");

if(!AcceptedRoles.contains(role))
return LunaMsg.send("**لا يمكن إعطاء هذه الرتبة**", "@");

args = args.filter(item => item !== args[0])

args.forEach(async user => {
user = user.replace("<", "");
user = user.replace("@", "");
user = user.replace(">", "");
user = user.replace("!", "");

if (parseInt(user) != `NaN`) {
await PlayerSystemFunctions.GiveRole(guildid,user,role)
}
});

LunaMsg.send(`**تم توزيع بنجاح <@&${role}>**`,"@")
}
so you mean i change give role function to await 🤣 it's old code sorry 🤣 thank of you help i will try to make sure all my functions as async and await for them
Want results from more Discord servers?
Add your server