Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- import datetime
- import matplotlib.pyplot as plt
- import numpy as np
- intents = discord.Intents.all()
- client = commands.Bot(command_prefix = 'cs!', intents=intents) # You can change the prefix to your taste
- # makes sure it can only be ran by one person
- def user_check(ctx):
- return ctx.author.id == 123 # Insert user ID of only person who can run commands
- # activation procedure
- @client.event
- async def on_ready():
- print('Activated!')
- # This is just a test command to see if the bot works and responds to the API
- @client.command()
- async def ping(ctx):
- await ctx.send(f'**Returned at:** {round(client.latency * 1000)}ms')
- @client.command()
- @commands.check(user_check)
- async def run(ctx):
- # General Variables
- bot_role = ctx.guild.get_role(788223715669442580) # Need to specify a singular role for ALL BOTS
- bots = len(bot_role.members)
- total_members = int(ctx.guild.member_count - (bots))
- date = datetime.datetime.now()
- todays_date = date.strftime("%A, %B %d, %Y")
- # Party Roles ID
- gop = ctx.guild.get_role(123) # FIND THE ROLE ID OF EACH ROLE
- dem = ctx.guild.get_role(123) # FIND THE ROLE ID OF EACH ROLE
- lib = ctx.guild.get_role(123) # FIND THE ROLE ID OF EACH ROLE
- ref = ctx.guild.get_role(123) # FIND THE ROLE ID OF EACH ROLE
- ind = ctx.guild.get_role(123) # FIND THE ROLE ID OF EACH ROLE
- soc = ctx.guild.get_role(123) # FIND THE ROLE ID OF EACH ROLE
- # Add more if you have more
- # Number of Members in Role
- total_gop = len(gop.members)
- total_dem = len(dem.members)
- total_lib = len(lib.members)
- total_ref = len(ref.members)
- total_soc = len(soc.members)
- # Add more if you have more
- major_parties = (total_gop, total_dem, total_lib, total_ref, total_registered_ind, total_soc)
- sum_mp = int(sum(major_parties))
- other_parties = int(total_members - sum_mp)
- # Pie Chart
- y = np.array([int(total_gop), int(total_dem), int(total_lib), int(total_ref), int(total_soc), int(total_registered_ind), int(other_parties)]) # Add more if you have more
- parties = [f"Republicans, {round(float(total_gop/total_members) * 100, 1)}%",
- f"Democrats, {round(float(total_dem/total_members) * 100, 1)}%",
- f"Libertarians, {round(float(total_lib/total_members) * 100, 1)}%",
- f"Reform, {round(float(total_ref/total_members) * 100, 1)}%",
- f"Socialists, {round(float(total_soc / total_members) * 100, 1)}%",
- f"Independents, {round(float(total_registered_ind/total_members) * 100, 1)}%",
- f"Unaffiliated/Other, {round(float(other_parties/total_members) * 100, 1)}%"
- ]
- partisan_colors = ["red", "blue", "yellow", "#00a889", "#7c0e0e", "#6e1cba", "#ededed"] # Make sure partisan colors are in the same pattern as the Pie Chart code block above it
- plt.pie(y, labels=parties, colors=partisan_colors)
- filename = date.strftime("%m-%d-%y")
- plt.savefig(f'C:/Location/{filename}.png') # Location where to save the pie charts
- pie_chart = discord.File(f'C:/Location/{filename}.png'g', filename=f"{filename}.png") # Find the file location
- embed = discord.Embed(
- title="Census Information",
- description=f'**Census Date:** `{todays_date}`'
- f'\n**Census Year (RP)**: `2010`', # Change the RP year or remove it with the \n entirely
- color=0x4287f5 # Change the color of the embed if you want. Hex code ALWAYS starts with '0x'
- )
- # Raw Numbers
- embed.add_field(name="Total Members", value=str(total_members), inline=True)
- embed.add_field(name="Total Republicans", value=str(total_gop), inline=True)
- embed.add_field(name="Total Democrats", value=str(total_dem), inline=True)
- embed.add_field(name="Total Libertarians", value=str(total_lib), inline=True)
- embed.add_field(name="Total Reform", value=str(total_ref), inline=True)
- embed.add_field(name="Total Socialists", value=str(total_soc), inline=True)
- embed.add_field(name="Total Registered Independents", value=str(total_registered_ind), inline=True)
- embed.add_field(name="Other Parties/Unaffiliated", value=str(other_parties), inline=True)
- # Percentages
- embed.set_image(url=f"attachment://{filename}.png")
- await ctx.send(file=pie_chart, embed=embed)
- client.run('BOT TOKEN') # Insert a bot token so the bot actually works
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement