├── README.md └── main.py /README.md: -------------------------------------------------------------------------------- 1 | ## What it is 2 | ##### A discord bot thats fun to use and gets chat active. 3 | ![image](https://user-images.githubusercontent.com/98252854/198720989-f3833d12-a674-4b89-8ef4-ec90dd8b539f.png) 4 | 5 | # 📝-Setup-📝 6 | - Watch the [video](https://www.youtube.com/watch?v=YsqWb35eobg&t=6s) to learn how to setup mongo. 7 | - Fill in all required info for connecting to mongo in the code 8 | - Make a bot on [discord developer portal](https://discord.com/developers/applications). 9 | - Put the bot token at the bottom. 10 | - Run the file or use a online hoster. 11 | # 📜-Features-📜 12 | - Mines command (5x5 grid of bombs amount of bombs up to user). 13 | - Tip command to share money with other users. 14 | - Login command to make it more interactive. 15 | - Balance command to check your balance and other users. 16 | ## 📝-More stuff comming soon-📝 17 | - Crash 18 | - Cases 19 | - Towers 20 | - Cups 21 | - Jackpot 22 | ### More info 23 | ###### All info is saved to a online database the curent bot uses mongo. 24 | ###### Send a pull request if u want to help update or think you can make code better than current state. 25 | # 26 | # 27 | ###### all code is free to use and open source and available to repurpose and sell! 28 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | import discord 3 | from discord import app_commands 4 | from pymongo import MongoClient 5 | import math 6 | 7 | #simple code to use slash commands 8 | class aclient(discord.Client): 9 | def __init__(self): 10 | super().__init__(intents = discord.Intents.all()) 11 | self.synced = False 12 | async def on_ready(self): 13 | await self.wait_until_ready() 14 | if not self.synced: 15 | await tree.sync() 16 | self.synced = True 17 | print("Bot is online") 18 | 19 | client = aclient() 20 | tree = app_commands.CommandTree(client) 21 | 22 | #connect to database 23 | mongo_url = '' #connection string 24 | cluster = MongoClient(mongo_url) 25 | db = cluster[''] #collection name 26 | collection = db[''] #database name 27 | 28 | @tree.command(name = 'login', description='login to your account') #simple login command to get user id and set balance 29 | async def login(interaction: discord.Interaction): 30 | user = interaction.user.id 31 | valid = False 32 | user_info = collection.find({"user": user}) 33 | for user_info in user_info: 34 | valid = True 35 | if valid == True: 36 | em = discord.Embed(description=f"**<@{user}>**You are already logged in.", color=0x0025ff) 37 | await interaction.response.send_message(embed=em) 38 | return 0 39 | else: 40 | post = {'user': user, 'balance': 500.00} 41 | collection.insert_one(post) 42 | em = discord.Embed(description=f"**<@{user}>**Logged in!\nBalance $500", color=0x0025ff) 43 | await interaction.response.send_message(embed=em) 44 | 45 | @tree.command(name = 'balance', description='checm your balance') 46 | async def balance(interaction: discord.Interaction, user : discord.Member = None): 47 | if user == None: 48 | user = interaction.user.id 49 | valid = False 50 | user_info = collection.find({"user": user}) 51 | for user_info in user_info: 52 | valid = True 53 | if not valid: 54 | em = discord.Embed(description='**You are not logged in, use /login to login**', color=0x0025ff) 55 | await interaction.response.send_message(embed=em) 56 | return 0 57 | balance = user_info['balance'] 58 | if balance <= 0: 59 | em = discord.Embed(description=f'**Balance: {balance}, resetting to 500**', color=0x0025ff) 60 | await interaction.response.send_message(embed=em) 61 | return 0 62 | balance = f"{balance:.2f}" 63 | em = discord.Embed(description=f'**Balance: ${balance}**', color=0x0025ff) 64 | await interaction.response.send_message(embed=em) 65 | return 0 66 | else: 67 | userid = user.id 68 | valid = False 69 | user_info = collection.find({"user": userid}) 70 | for user_info in user_info: 71 | valid = True 72 | if valid == True: 73 | balance = user_info['balance'] 74 | em = discord.Embed(description=f"** {user.mention}'s Balance: ${balance}**", color=0x0025ff) 75 | await interaction.response.send_message(embed=em) 76 | return 0 77 | 78 | 79 | @tree.command(name = 'tip', description='tip') 80 | async def tip(interaction: discord.Interaction, amount : int, recipient : discord.Member): 81 | local_user = interaction.user.id 82 | recipient_id = recipient.id 83 | valid = False 84 | local_user_info = collection.find({"user": local_user}) #check if person sending money is logged in 85 | for local_user_info in local_user_info: 86 | valid = True 87 | 88 | if valid == True: 89 | recipient_info = collection.find({"user": recipient_id}) #get all needed info the the user we need to send money to 90 | valid = False 91 | 92 | for recipient_info in recipient_info: 93 | valid = True 94 | 95 | if valid == True: 96 | local_balance = local_user_info['balance'] 97 | new_balance = local_balance - amount 98 | 99 | recipient_balance = recipient_info['balance'] 100 | recipient_new_bal = recipient_balance + amount 101 | 102 | collection.update_one({"user": recipient_id}, {"$set": {"balance": recipient_new_bal}}) #give the money to the person 103 | collection.update_one({"user": local_user}, {"$set": {"balance": new_balance}}) #take the money from the person sending it 104 | 105 | em = discord.Embed(description=f'{interaction.user.mention} sent ${amount} to {recipient.mention}', color=0x0025ff) 106 | await interaction.response.send_message(embed=em) 107 | 108 | @tree.command(name = 'mines', description='Mines gamemode: 5x5 grid of possible mines') 109 | async def mines(interaction: discord.Interaction, bomb_amount : int, bet_amount : int): 110 | if bet_amount < 5: #bet amt check 111 | em = discord.Embed(description=f"Bet amount must be higher than 5", color=0x0025ff) 112 | await interaction.response.send_message(embed=em) 113 | return 0 114 | if bomb_amount > 24 or bomb_amount <= 0: 115 | em = discord.Embed(description='Number to high', color=0x0025ff) 116 | await interaction.response.send_message(embed=em) 117 | return 0 118 | 119 | user = interaction.user.id 120 | valid = False 121 | user_info = collection.find({"user": user}) 122 | for user_info in user_info: 123 | valid = True 124 | 125 | if valid == False: 126 | em = discord.Embed(description='You are not logged in, use /login to login', color=0x0025ff) 127 | await interaction.response.send_message(embed=em) 128 | return 0 129 | 130 | balance = user_info['balance'] 131 | 132 | if bet_amount > balance: 133 | em = discord.Embed(description='You do not have enough', color=0x0025ff) 134 | await interaction.response.send_message(embed=em) 135 | return 0 136 | 137 | #math stuff to find the multiplier of mines and click amount stake multi cus they same 138 | def nCr(n,r): 139 | f = math.factorial 140 | return f(n) // f(r) // f(n-r) 141 | 142 | #also math stuff to find multi stake multi cus they same 143 | def multiplier_math(bombs, clicks): 144 | return 0.94 * nCr(25, clicks) / nCr(25 - bombs, clicks) 145 | 146 | #take the bet amt from the users balance 147 | take_away = balance - bet_amount 148 | collection.update_one({"user": user}, {"$set": {"balance": take_away}}) 149 | balance = user_info['balance'] 150 | 151 | #grid stuff 152 | bomb_location = [] 153 | #25 total (0,24) 154 | grid = ['🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦'] 155 | #another grid to use when sending clicked spots without revealing bomb location 156 | s_grid = ['🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦','🟦'] 157 | 158 | #convert bomb amt to actual bombs 159 | count = 0 160 | while bomb_amount > count: 161 | a = randint(0,24) #0,24 since grid starts at 0 162 | b = a + 1 # + 1 so its the same as 1,25 163 | if b in bomb_location: 164 | continue 165 | bomb_location.append(b) 166 | grid[a] = '💥' #make bomb locations equal to emoji on the grid 167 | count += 1 # add 1 so we can keep track of how much times we ran it 168 | 169 | em = discord.Embed(color=0x0025ff) 170 | #this part will be in the description 171 | em.add_field(name = 'Grid', value = s_grid[0]+s_grid[1]+s_grid[2]+s_grid[3]+s_grid[4]+"\n"+s_grid[5]+s_grid[6]+s_grid[7]+s_grid[8]+s_grid[9] + "\n" + 172 | s_grid[10]+s_grid[11]+s_grid[12]+s_grid[13]+s_grid[14] + "\n" + s_grid[15]+s_grid[16]+s_grid[17]+s_grid[18]+s_grid[19] + '\n' + s_grid[20] + s_grid[21] + \ 173 | s_grid[22] + s_grid[23] + s_grid[24] + f"\nBomb Amount: {bomb_amount}\nBet Amount: {bet_amount}\nWhere do you want to click? (1,25)") #prob a better way to do this, its jus the way i do it 174 | await interaction.response.send_message(embed=em) 175 | 176 | #command to check who used message 177 | def check(m): 178 | return m.author.id == interaction.user.id 179 | 180 | clicked_spots = [] 181 | global multiplier 182 | multiplier = 1 183 | multi = -0.5 184 | while True: 185 | #get user input and check if its equal to person who did command 186 | message = await client.wait_for('message', check=check) 187 | 188 | #check if user wants to cash out 189 | if message.content == 'yes': 190 | balance = user_info['balance'] 191 | collection.update_one({"user":user}, {"$set": {"balance": balance + (bet_amount * multi)}}) # add the mone to the users bal 192 | #use grid instead of s_grid bcs grid has bomb location saved 193 | em = discord.Embed(description='**Cashed out!** \n' + grid[0]+grid[1]+grid[2]+grid[3]+grid[4]+"\n"+grid[5]+grid[6]+grid[7]+grid[8]+grid[9] + "\n" + \ 194 | grid[10]+grid[11]+grid[12]+grid[13]+grid[14] + "\n" + grid[15]+grid[16]+grid[17]+grid[18]+grid[19] + '\n' + grid[20] + grid[21] + \ 195 | grid[22] + grid[23] + grid[24] + f"\nProfit: {bet_amount * multi:.2f}", color=0x0025ff) 196 | await interaction.followup.send(embed=em) 197 | return 0 198 | 199 | #check if user already clicked in spot they want to click 200 | spot = message.content 201 | if spot in clicked_spots: 202 | balance = user_info['balance'] 203 | collection.update_one({"user":user}, {"$set": {"balance": balance + (bet_amount * multi)}}) #give them current profit and end game 204 | em = discord.Embed(description='Already clicked there \n', color=0x0025ff) 205 | await interaction.followup.send(embed=em) 206 | return 0 207 | clicked_spots.append(spot) 208 | 209 | try: 210 | if int(spot) in bomb_location: 211 | spot = int(spot) - 1 212 | grid[int(spot)] = '❌' #what u want the spot do be if u click and theres a bomb 213 | 214 | # add money to someones balance when users lose (cant let money go in void :)) 215 | owner_info = collection.find_one({"user": 1021501304461348864}) 216 | owner_balance = owner_info['balance'] 217 | collection.update_one({"user": 1021501304461348864}, {"$set": {"balance": owner_balance + bet_amount}}) #send money to owner balance 218 | mention = interaction.user.mention 219 | em = discord.Embed(description=f'**{mention}\nYou Lost!**\n' + grid[0]+grid[1]+grid[2]+grid[3]+grid[4]+"\n"+grid[5]+grid[6]+grid[7]+grid[8]+grid[9] + "\n" + \ 220 | grid[10]+grid[11]+grid[12]+grid[13]+grid[14] + "\n" + grid[15]+grid[16]+grid[17]+grid[18]+grid[19] + '\n' + grid[20] + grid[21] + \ 221 | grid[22] + grid[23] + grid[24] + f"\nLost: {bet_amount}", color=0x0025ff) 222 | await interaction.followup.send(embed=em) 223 | return 0 224 | except: 225 | await interaction.followup.send("Try again") 226 | balance = user_info['balance'] 227 | collection.update_one({"user":user}, {"$set": {"balance": balance + bet_amount}}) 228 | return 0 229 | temp_s = int(spot) - 1 230 | #we use a try incase they put a number larger than 25 meaning out of range for the list 231 | try: 232 | s_grid[int(temp_s)] = '🟩' #make the clicked spot equal to specific emoji 233 | except: 234 | await interaction.followup.send("to high of numeber try again") 235 | balance = user_info['balance'] 236 | collection.update_one({"user":user}, {"$set": {"balance": balance + bet_amount}}) 237 | return 0 238 | 239 | grid[int(spot) - 1] = '🟩' 240 | 241 | multiplier += 1 242 | multi = multiplier_math(bomb_amount, multiplier) 243 | em = discord.Embed(description= s_grid[0]+s_grid[1]+s_grid[2]+s_grid[3]+s_grid[4]+"\n"+s_grid[5]+s_grid[6]+s_grid[7]+s_grid[8]+s_grid[9] + "\n" + \ 244 | s_grid[10]+s_grid[11]+s_grid[12]+s_grid[13]+s_grid[14] + "\n" + s_grid[15]+s_grid[16]+s_grid[17]+s_grid[18]+s_grid[19] + '\n' + s_grid[20] + s_grid[21] + \ 245 | s_grid[22] + s_grid[23] + s_grid[24] + f"\nMultiplier: {multi:.2f}\nCashout? (yes) or (1,25)", color=0x0025ff) 246 | await interaction.followup.send(embed=em) 247 | 248 | 249 | 250 | client.run('discord bot token') 251 | --------------------------------------------------------------------------------