Skip to content

check against roles not channels #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/utils/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,29 @@ export async function createRoles<T extends IRole>(
const found_role = checkForRole(guild, clean_role_name, role_doc.ROLE_ID);

if (found_role === undefined) {
console.log(
chalk.red(
`Couldn't find role: ${clean_role_name} with id: ${role_doc.ROLE_ID}`
)
);
const role = await guild.roles.create({
name: clean_role_name,
});

// save role id to database
role_doc.ROLE_ID = role.id;
await role_doc.save();

// Print the role id to the console
console.log(chalk.yellow(`Created role: ${role.name}\tid: ${role?.id}`));
} else {
// If the role already exists, update it to match the db then print the id to the console
role_doc.ROLE_ID = found_role.id;
role_doc.ROLE_NAME = found_role.name;
await role_doc.save();

console.log(
chalk.yellow(`Role exists: ${found_role.name}\tid: ${found_role.id}`)
chalk.green(`Role exists: ${found_role.name}\tid: ${found_role.id}`)
);
}
await role_doc.save();
}
}
/**
Expand All @@ -195,15 +198,15 @@ export function checkForRole(
role_id?: string
) {
if (role_id !== undefined) {
const found_role = guild.channels.cache.find((role) => {
const found_role = guild.roles.cache.find((role) => {
return role.id === role_id;
});
if (found_role !== undefined) {
return found_role;
}
}
if (role_name !== undefined) {
const found_role = guild.channels.cache.find((role) => {
const found_role = guild.roles.cache.find((role) => {
return role.name === role_name;
});
if (found_role !== undefined) {
Expand Down