Skip to content

Discord bot that automatically assigns roles(from spreadsheet) to users found in a Google Sheet

License

Notifications You must be signed in to change notification settings

supreen/form2role-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Form2Role-Bot:

About

This is the simplified version of talios0's and The24thDS's bot. The bot assigns the roles (according to the 2nd,3rd,4th and 5th column of the spreadsheet) to the usernames found in a 1st column of Google Sheet. Made possible by the amazing Discord.js library. Please note that the bot start detecting the data from 2nd row of spreadsheet.

Motivation

Did you ever want to add some kind of authentication to your Discord server? Maybe you want only people with a certain email domain to have access to some channels. Use a form to collect the required data and then set up this bot to automatically assign roles to everyone found in the Google Sheet.

Required fields

The only field that you must have in your Google Form and Google Sheet is the DiscordID. Your DiscordID it's made up of your username and the discriminator, and it looks like this: SomeSexyUsername#4565. The bot needs it to identify users and assign roles to them.(When you selected "UN" in discord.config)

With new update, now you can also add USERID which is unique id and can be found by right clicking on the username and clicking on "COPY ID" it will be something like "696051693519503421" (When you selected "UI" in discord.config).

How to get your Google details

API key

  • Go to https://console.developers.google.com
  • Login and Agree to the Terms of Service
  • Create a Project by pressing "Create Project" on the right-hand side
  • Click "Create", give the project a name and then "Create" again.
  • Once the dashboard loads, click on "ENABLE APIS AND SERVICES" in blue text.
  • Search for "Sheets" and click on "Google Sheets API" and then "ENABLE"
  • Click on "Credentials" on the left side of the page.
  • Select "Create credentials" and then "API Key"

Spreadsheet ID

Range

If the column that contains the Discord IDs is B and the IDs start from row 2 then the range value (don't touch it, if you don't know what you are doing)

How to setup a Discord bot

You will need a bot token, to generate one follow these steps:

  • Go to https://discordapp.com/developers and login
  • Create an application and give it a name and a description
  • Select "Save Changes" at the bottom right and then navigate to the "Bot" section on the left-hand side.
  • There, create a bot user by clicking on "Add Bot". After confirming, reveal the token.

Invite the bot to your discord server:

  • Go to OAuth2 section of your developer application
  • Under SCOPES check bot
  • Under BOT PERMISSIONS check Manage Roles
  • Now go to the url generated in the SCOPES section and invite the bot to your server
  • Make sure the bot role is above the roles it has to assign

Configuration steps

  • Install Node.JS
  • Download the latest bot version from the release tab and unzip it
  • Go to the config folder, copy and paste the config files
  • Open discord.json and complete your API key, your Spreadsheet id and Token (See How to get your Google details). All of these are strings, so make sure they are enclosed in quotation marks. (don't mess with empty arrays and variable such as usernamesp and roles)
  • Go back to the root folder, open a terminal here and run these commands: npm install, wait for it to finish then run npm start.
  • Run "npm install discord.js" , "npm install express" and "npm install request" (if required)
  • Congratulations, if you did everything correctly you now have Form2Role bot running.

More info

  • The bot checks the sheet for new users and roles every minute. However you can change that in the code. i.e refresh rate in discord.json. it is in miliseconds
  • The bot only supports upto 4 roles in column 2, 3, 4 ,5
  • Once you enter a "sexyusername#1111" in the spreadsheet, you can no longer control its roles from dicord. the bot will revert the roles back to the roles mentioned in the spreadsheet.
  • Future updates will include mainly bug fixes.
  • Contributions are highly apreciated.

New updates on 28/06/2020

  • Now the bot can detect userid instead of username. change the value of "usernameorid" in discord.json. i.e ["username":"UN"] for detecting username and ["username":"UI"] for detecting userid
  • We just realized that bot was throwing "missing permission" error when it was trying to remove unremovable roles. there now you can put unremoveable roles or the roles you dont want this bot to remove in "unremoveableroles" in discord.json. i.e "unremoveableroles":["bot","serverboost"]
  • The bot was doing nothing when all roles were removed, it detects and removes all roles now
  • Now it throws time in console when the bot assign or remove roles of a user
  • New Information updates on 22/06/2022


    Always add "@everyone" and other unremovable roles in unremovable roles under config/discord.json


    You should manually give more permission to your bot roles as shown in the picture below

  • Right click on the server "icon"
  • Click on "Server Setting" from drop menu"
  • Click "Roles" from the drop menu of "server settings
  • Click "Roles" menu click on the "role" assigned to your bot
  • Click "Roles" menu click on the "role" assigned to your bot
  • Go to "Permissions" Tab and give all permissions to your bot
  • Image of Permission

    Your bot role much be higher than another role as shown in the picture below

  • Right click on the server "icon"

  • Click on "Server Setting" from drop menu"
  • Click "Roles" from the drop menu of "server settings
  • drag the bot role above all roles
  • Image of higher role


    New demo added on 22/06/2022

  • Spreadsheet link:https://docs.google.com/spreadsheets/d/1p1GiIqUUy2b-HcsaCJFHu_ZYQ2nWKZ2zGXmEmu9RrNE/edit#gid=0
  • Discord chaneel: https://discord.com/channels/715245634218885131/715245634898100256
  • Free free to edit the roles preferable just checking and unchecking the roles. please be cautious, a wrong move can crash the bot.

    Consider buying me a coffee, if you loved my work.

  • https://www.buymeacoffee.com/suprin

    If you are still finding it hard, Hire me

  • https://sobdar.com/order (you get 30% off here and you can also put your query there)
  • https://www.fiverr.com/supreen

    For more contact please visit: