first commit
This commit is contained in:
commit
d7e0e3eb2c
110
example-bot.py
Normal file
110
example-bot.py
Normal file
@ -0,0 +1,110 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from private.config import token
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
"""
|
||||
TODO:
|
||||
- [ ] The whole Ahoj think
|
||||
- [ ] Case sensitivity in ahoj function
|
||||
- [ ] Close bot in specific chanel
|
||||
- [ ] Git ignore and where to store TOKEN
|
||||
- [ ] Embeds means what?
|
||||
- [ ] Seznam sprostych slov a reakci na ne
|
||||
"""
|
||||
|
||||
|
||||
#intents = discord.Intents.default()
|
||||
#intents.message_content = True
|
||||
|
||||
#bot = commands.Bot(command_prefix='$', intents=intents)
|
||||
|
||||
|
||||
os.chdir("/home/godot/Documents/scripts/discord-bot.py")
|
||||
#os.chdir("/opt/disbot")
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
|
||||
#client = discord.Client(intents=intents)
|
||||
bot = commands.Bot(command_prefix='$', intents=intents)
|
||||
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print(f'We have logged in as {bot.user}')
|
||||
|
||||
"""
|
||||
@bot.event
|
||||
async def on_message(message):
|
||||
|
||||
# test is bot is not responding to itself
|
||||
if message.author == bot.user:
|
||||
return
|
||||
|
||||
# hello reaction
|
||||
if message.content.startswith('ahoj'):
|
||||
await message.channel.send('Zdravím miláčkové!')
|
||||
"""
|
||||
|
||||
@bot.command()
|
||||
async def balance(ctx):
|
||||
# test if acount is opend and makes on if not
|
||||
await open_account(ctx.author)
|
||||
|
||||
user = ctx.author
|
||||
users = await get_bank_data()
|
||||
|
||||
wallet_amt = users[str(user.id)]["wallet"]
|
||||
|
||||
em = discord.Embed(title = f"{ctx.author.name}'s balance",color = discord.Color.red())
|
||||
em.add_field(name = "Wallet balance", value = wallet_amt)
|
||||
await ctx.send(embed = em)
|
||||
|
||||
|
||||
async def open_account(user):
|
||||
# opens json file to found if user id is present
|
||||
|
||||
users = await get_bank_data()
|
||||
|
||||
# tests presence
|
||||
if str(user.id) in users:
|
||||
return False
|
||||
else:
|
||||
users[str(user.id)] = {}
|
||||
users[str(user.id)]["wallet"] = 100
|
||||
|
||||
# saves a new data in json
|
||||
with open("mainbank.json", "w") as f:
|
||||
json.dump(users,f)
|
||||
return True
|
||||
|
||||
|
||||
# opens json stored data
|
||||
async def get_bank_data():
|
||||
with open("mainbank.json", "r") as f:
|
||||
users = json.load(f)
|
||||
|
||||
return users
|
||||
|
||||
# for testing perpesis only
|
||||
@bot.command()
|
||||
async def beg(ctx):
|
||||
await open_account(ctx.author)
|
||||
|
||||
users = await get_bank_data()
|
||||
user = ctx.author
|
||||
|
||||
earnings = 10
|
||||
|
||||
await ctx.send(f"Someone just gave you {earnings} coins")
|
||||
|
||||
users[str(user.id)]["wallet"] += earnings
|
||||
|
||||
with open("mainbank.json", "w") as f:
|
||||
json.dump(users,f)
|
||||
|
||||
bot.run(token)
|
||||
1
mainbank.json
Normal file
1
mainbank.json
Normal file
@ -0,0 +1 @@
|
||||
{"412092791733354521": {"wallet": 120}, "232593965910720514": {"wallet": 100}}
|
||||
Loading…
x
Reference in New Issue
Block a user