Implement Bloxy.py to Discord bots!

Introduction

Hi there! my name is Icy! i am a web developer who has passion for creating roblox games! In todays tutorial, we will be learning how to implement Bloxy.py into discord bots in python!

Getting started

first things first we need to install Bloxy.py into our library. I the terminal, Type the following…

# installing and upgrade pip
$ python -m pip install --upgrade pip

# Installing the Module
$ pip install git+https://github.com/IcyDevv/bloxypy.git

After we install our module we need to install discord.py, type in the following in our terminal…

# installing discord
$ pip install git+https://github.com/Rapptz/discord.py.git

Programming our bot

Ok! so now that we have ur modules installed. We can now program our bot.

Step 1

We need our variables so we can program our bot! type in the following…

import discord
import bloxy
import json
import asyncio
from discord.ext import commands

client = discord.Client()
bloxyclient = bloxy.Client()
group = bloxy.Group()
bot = commands.Bot(command_prefix="!")

Step 2

Ok so now we have our variables. Now we can start programming our bot.
Type in the following…

@client.event
async def on_ready():
   print("Bot is online")

@bot.command(aliases="bal")
async def balance(ctx):
	await open_account(ctx.author)

	user = ctx.author

	users = await bank_data()

	bank = users[str(user.id)]["bank"]

	em = discord.Embed(title = f"{ctx.author.name}'s balance", color = discord.Color.red())
	em.add_field(name = "Coins", value = bank)
	await ctx.send(embed = em)


async def open_account(user):
	users = await bank_data()

	if str(user.id) in users:
		return False
	else:
		users[str(user.id)] = {}
		users[str(user.id)]["bank"] = 0

	with open("bank.json", "w") as f:
		json.dump(users, f)
	return True


async def bank_data():
	with open("bank.json", "r") as f:
		users = json.load(f)

	return users


async def update_bank(user, change = 0, mode = 'bank'):
	users = await bank_data()

	users[str(user.id)][mode] += change

	with open("bank.json", "w") as f:
		json.dump(users, f)

	bal = users[str(user.id)]["bank"]
	return bal

@bot.command(aliases="col")
async def collect(ctx, userid = None)
   if userid:
      await open_account(ctx.author)

	user = ctx.author

	users = await bank_data()

	earnings = 1000

	await ctx.send(f"You got {earnings} coins!")

	users[str(user.id)]["bank"] += earnings

	with open("bank.json", "w") as f:
		json.dump(users, f)

async def main(UserId):
   user = bloxyclient.get_user_by_id(UserId)
   group = bloxyclient.get_group(1234567) -- your group id
   usergroup = bloxyclient.user_is_in_group(group, user)

    if usergroup:
       collect()
    else:
       print("Either user or group does not exist")

Step 3

now that we have all our code done. We can run the code and test the code. but before we need to type in the following…

asyncio.run(main())
bot.run("TOKEN HERE")

Step 4

well now were done! Wait, where not quite done yet we need to make our json file. in whatever studio your using. create a file named “bank.json” and type in these very simple brackets.

{

}

Conclusion

Congrats! you made your first discord bot with bloxy.py! Hope this tutorial help you alot.

Link to bloxy.py: here
Link to wiki: wiki

Thanks for reading! :slightly_smiling_face:

2 Likes