LengoLabs / qbot

Qbot is an advanced, easy to setup, free, and unbranded Discord-Roblox ranking bot. If at any time during setting it up you need assistance, you can join the support server.
https://discord.gg/J47m7t4
MIT License
75 stars 136 forks source link

How do I make the webhook execute a command? #36

Closed frostgit-dev closed 4 years ago

frostgit-dev commented 4 years ago

const roblox = require('noblox.js'); const chalk = require('chalk'); require('dotenv').config();

async function getRankName(func_group, func_user){ let rolename = await roblox.getRankNameInGroup(func_group, func_user); return rolename; }

async function getRankID(func_group, func_user){ let role = await roblox.getRankInGroup(func_group, func_user); return role; }

async function getRankFromName(func_rankname, func_group){ let roles = await roblox.getRoles(func_group); let role = await roles.find(rank => rank.name == func_rankname); if(!role){ return 'NOT_FOUND'; } return role.rank; }

exports.run = async (client, message, args) => { if(!message.member.roles.cache.some(role =>["[-] Bot", "Solea Owners", "Ron"].includes(role.name))){ return message.channel.send({embed: { color: 16733013, title: 'Access Denied!', description: "You need to have permissions from ven#2175 to run this command, he said only bots can.", author: { name: message.author.tag, icon_url: message.author.displayAvatarURL() } }}) }

if(message.author.bot);

if(message.author.webhook);

let username = args[0];
if(!username){
    return message.channel.send({embed: {
        color: 16733013,
        title: 'Oops!',
        description: "The username argument is required.",
        author: {
            name: message.author.tag,
            icon_url: message.author.displayAvatarURL()
        },
        footer: {
        text: 'Solea Ranking',
        icon_url: `https://cdn.discordapp.com/attachments/746770154821517394/747027560860352582/1e73e4fc65899dadf0e0db20dfe68dc2.png`
    }
    }});
}
let rank = Number(args[1]);
let newrank;
if(!rank){
    let midrank = args.slice(1).join(' ');
    if(!midrank){
        return message.channel.send({embed: {
            color: 16733013,
            title: 'Sorry!',
            description: "The rank id is required.",
            author: {
                name: message.author.tag,
                icon_url: message.author.displayAvatarURL()
            },
           footer: {
        text: 'Solea Ranking',
        icon_url: `https://cdn.discordapp.com/attachments/746770154821517394/747027560860352582/1e73e4fc65899dadf0e0db20dfe68dc2.png`
    }
        }});
    }
    newrank = await getRankFromName(midrank, Number(process.env.groupId));
} else {
    newrank = rank;
}
let id;
try {
    id = await roblox.getIdFromUsername(username);
} catch {
    return message.channel.send({embed: {
        color: 16733013,
        description: `Oops! ${username} is not a Roblox user. Perhaps you misspelled?`,
        author: {
            name: message.author.tag,
            icon_url: message.author.displayAvatarURL()
        },
        footer: {
        text: 'Solea Ranking',
        icon_url: `https://cdn.discordapp.com/attachments/746770154821517394/747027560860352582/1e73e4fc65899dadf0e0db20dfe68dc2.png`
    }
    }});
}
let rankInGroup = await getRankID(Number(process.env.groupId), id);
let rankNameInGroup = await getRankName(Number(process.env.groupId), id);
if(Number(process.env.maximumRank) <= rankInGroup){
    return message.channel.send({embed: {
        color: 16733013,
        title: 'Sorry!',
        description: "This rank cannot be ranked by this bot.",
        author: {
            name: message.author.tag,
            icon_url: message.author.displayAvatarURL()
        },
        footer: {
        text: 'Solea Ranking',
        icon_url: `https://cdn.discordapp.com/attachments/746770154821517394/747027560860352582/1e73e4fc65899dadf0e0db20dfe68dc2.png`
    }
    }});
}
if(newrank == 'NOT_FOUND'){
    return message.channel.send({embed: {
        color: 16733013,
        title: 'Sorry!',
        description: "The specified rank could not be found.",
        author: {
            name: message.author.tag,
            icon_url: message.author.displayAvatarURL()
        },
        footer: {
        text: 'Solea Ranking',
        icon_url: `https://cdn.discordapp.com/attachments/746770154821517394/747027560860352582/1e73e4fc65899dadf0e0db20dfe68dc2.png`
    }
    }});
}
let setRankResponse;
try {
    setRankResponse = await roblox.setRank(Number(process.env.groupId), id, newrank);
} catch (err) {
    console.log(chalk.red('An error occured when running the setrank command: ' + err));
    return message.channel.send({embed: {
        color: 16733013,
        title: 'Sorry!',
        description: `An unexpected error has occured. It has been logged to the bot console.`,
        author: {
            name: message.author.tag,
            icon_url: message.author.displayAvatarURL()
        },
        footer: {
        text: 'Solea Ranking',
        icon_url: `https://cdn.discordapp.com/attachments/746770154821517394/747027560860352582/1e73e4fc65899dadf0e0db20dfe68dc2.png`
    }
    }});
}
let newRankName = await getRankName(Number(process.env.groupId), id);
message.channel.send({embed: {
    color: 9240450,
    title: 'Access Granted!',
    description: `Ranked ${username} to ${setRankResponse.name} (${setRankResponse.rank})`,
    author: {
        name: message.author.tag,
        icon_url: message.author.displayAvatarURL()
    },
    footer: {
        text: 'Solea Ranking',
        icon_url: `https://cdn.discordapp.com/attachments/746770154821517394/747027560860352582/1e73e4fc65899dadf0e0db20dfe68dc2.png`
    }
}});
if(process.env.logchannelid === 'false') return;
let logchannel = await message.guild.channels.cache.get(process.env.logchannelid);
logchannel.send({embed: {
   color: 2127726,
    title: 'Success!',
    description: `**Command Usage:** /ranc \n

Who used the command: <@${message.author.id}> \n Target User: ${username} \n Old Rank: ${rankNameInGroup} (${rankInGroup}) \n New Rank: ${setRankResponse.name} (${setRankResponse.rank})., footer: { text: 'Solea Ranking', icon_url:https://cdn.discordapp.com/attachments/746770154821517394/747027560860352582/1e73e4fc65899dadf0e0db20dfe68dc2.png }, timestamp: new Date(), thumbnail: { url:http://www.roblox.com/Thumbs/Avatar.ashx?x=150&y=150&format=png&username=${username}` } }}); }

frostgit-dev commented 4 years ago

The issue is: Cannot read property 'ROLES' of null

yogurtsyum commented 4 years ago

What is that big blob of code?

TypicallyShad commented 4 years ago

Please respond back with your code by using a code block & answer the question as mentioned by @yogurtsyum

Code blocks can be sent by wrapping your message with ```, this is just like the same system as Discord currently has. For further information on GitHub formatting, please check out the official guide here..

Ensure you also provide correct photo links, it seems that I cannot access the photo you have sent, thank you.

frostgit-dev commented 4 years ago

Fixed nvm.