Zanteri - Programs

Programmer, Writer, Whatever Else

ZanBot

      

import discord
import random
from discord import app_commands
from discord.ext import commands

intents = discord.Intents.default()
intents.message_content = True

#client = discord.Client(intents=intents)
bot = commands.Bot(command_prefix='$', intents = discord.Intents.all())

@bot.event
async def on_ready():
    print(f'We have logged in as {bot.user}')

##################################
########  SLASH COMMANDS  ########
##################################


#############################
#####    SLASH HELP     #####
#############################

#Declare Command
@bot.tree.command(name='help', description='Lists all commands from ZanBot')
#Starts async
async def help(interaction: discord.Interaction):
    #Sets commands as a list of commands
    commands = bot.tree.get_commands()

    #Start message
    help_message = '```'
    #For each command
    for command in commands:
        #Add command and description to help_message
        help_message += f'{command.name} - {command.description}\n'
    help_message += '```'

    #Send message
    await interaction.response.send_message(help_message)


#############################
#####      HELLO        #####
#############################

#Declare 'hello' Command
@bot.tree.command(name='hello', description='Tells you hello (In private)')
#Starts async
async def hello(interaction: discord.Interaction):
    #Sends message (ephemeral that only sending user can see)
    await interaction.response.send_message(f'Hello there {interaction.user.mention}!', ephemeral=True)


#############################
#####        SAY        #####
#############################

#Declare 'say' Command
@bot.tree.command(name='say', description='The bot repeats you')
#Adds description to argument
@app_commands.describe(arg = 'What should the bot say?')
#Starts async
async def say(interaction: discord.Interaction, arg: str):
    #Repeats arg
    await interaction.response.send_message(f'{interaction.user.name} said: "{arg}"')


##################################
######## PREFIX COMMANDS  ########
##################################

@bot.event
async def on_message(message):
    #If message is from this bot
    if message.author == bot.user:
        return
    
    if message.content.startswith('$ready'):

        try:

            synced = await bot.tree.sync()

            await bot.tree.sync(guild=message.guild)
            
            print(f'Synced {len(synced)} command(s)')
        except Exception as e:
            print(f'Error syncing command(s): {e}')
    
    #############################
    #####    PREFIX HELP    #####
    #############################

    #If message starts with $h
    if message.content.startswith('$h'):
        await message.channel.send('**$h:** Displays commands\n**$b:** Rolls boon dice, optional argument for number of dice. Default is 1\n'
                                   '**$c:** Rolls challenge dice, optional argument for number of dice. Default is 1\n'
                                   '**$v:** Rolls both boon and challenge dice, optional argument for number of dice. Boon is first, followed by challenge. Default is 1 if both or just challenge dice numbers are omitted\n'
                                   '**$q:** Displays a list of the names of all quirks')

    #If message starts with '$hello'
    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')

    #############################
    #####      BOON DIE     #####
    #############################

    #If message starts with '$b'
    if message.content.startswith('$b'):
        results = 0
        #J is count of dice rolled
        j = 0
        args = message.content.split()

        #If message contains argument
        if len(args) > 1:
            #Set i to number in arg
            i = int(args[1])
        else:
            #Else, default to 1
            i = 1
        while j < i:
            #Roll boon die
            if random.randint(1, 8) > 4:
                results += 1
            j += 1
        await message.channel.send(results)

    #############################
    #####   CHALLENGE DIE   #####
    #############################

    #If message starts with '$c'
    if message.content.startswith('$c'):
        results = 0
        #J is count of dice rolled
        j = 0
        args = message.content.split()

        #If message contains argument
        if len(args) > 1:
            #Set i to number in arg
            i = int(args[1])
        else:
            #Else, default to 1
            i = 1
        while j < i:
            #Roll challenge die
            roll = random.randint(1, 10)
            if roll > 4:
                results += 1

            j += 1
        await message.channel.send(results)

    #############################
    #####     BOTH DICE     #####
    #############################

    #If message starts with '$v'
    if message.content.startswith('$v'):
        b_results = 0
        c_results = 0
        #J is count of boon dice rolled, K for chal dice
        j = 0
        k = 0
        args = message.content.split()

        #Boon spot
        

        #If command and 1 arg (boon count)
        if len(args) == 2:

            try:
                #Set boon to number in arg
                i_boon = int(args[1])

            except:
                await message.channel.send('This command only numbers as arguments.')
                return

            #Set challenge to default
            i_chal = 1

        #If command and 2 args
        elif len(args) == 3:

            try:
                #Set boon and chal to number in arg
                i_chal = int(args[2])
                i_boon = int(args[1])

            except:
                await message.channel.send('This command only numbers as arguments.')
                return

        #If only the command, assume 1 for both
        elif len(args) == 1:
            
            #Else, default to 1
            i_boon = 1
            i_chal = 1

        else:
            await message.channel.send('This command only allows up to 2 arguments (# of boon dice, # of challenge dice).')
            return
        
        #DISPLAY THE AMOUNT OF DICE
        await message.channel.send(f'Rolling {i_boon} boon dice and {i_chal} challence dice:')

        #ROLL THE DICE
        while j < i_boon:
                #Roll challenge die
                if random.randint(1, 8) > 4:
                    b_results += 1
                j += 1
        while k < i_chal:
            #Roll challenge die
            if random.randint(1, 10) > 4:
                c_results += 1
            k += 1

        
        
        #DISPLAY RESULTS

        async for message in message.channel.history(limit=None):
            if message.author == bot.user:
                last_message = message
                break
        #print(last_message.content)
        await last_message.edit(content=f'{last_message.content} {b_results} boon(s), {c_results} challenge(s)')
        #await message.channel.send(f'{b_results} boon(s), {c_results} challenges')

    #############################
    #####   RANDOM QUIRKS   #####
    #############################

    #If message starts with '$q'
    if message.content.startswith('$q'):
        quirks = ['A Little Home in Taona', 'Animal Whisperer', 'Artisan', 'Aura Reader', 'Card Sharp', 'Chosen of the Black Counsil', 'Chromaturgy', 
                  'Disgraced Watch Officer', "Diviner's Ear", 'Dizzying Intellect', 'Dockworker', 'Elderleader', 'Escaped Final Vows', 'Everyman', 'Ex-Blooded', 'Ex-Con', 'Eye For Art', 
                  'Failed Apprentice', 'Family Ties', 'Fascination with the Occult', 'Former Soldier', 'Fresh-Faced', 'Friendly Rival', 'Gossip Monger', 
                  'Indebted', 'Iron Guts', 'Labor Camp Refugee', 'Legacy', 'Loan Shark', 'Looking to Get Out', 'Lucky Charm', 
                  'Master Artist', 'Master Chef', 'Master Musician', 'Memories of a Past Life', 'Mentor', 'Object Reader', 'Old Flame', 'Orphaned Scion', 
                  'Pet', 'Physicker', 'Privateer', 'Reader', 'Scribe-Perfect Memory', 'Shifted Allegations', 'Sibling in the Crew', 'Signature Weapon', 
                  'Slum Lord', 'Society School Training', 'Stage Musician', 'Street Hustler', 'Stunning', 'Taonan', 'Tinker', 'Trading Company Job', 'Twins', 
                  'Unnatural Healing', 'Vladich', 'Watcher in the Dark', 'Wraith Survivor']

        result = random.randint(1, len(quirks))

        await message.channel.send(f'You drew: {quirks[result]}')

bot.run(bot_key)


        
    

Requirements:

  • discord.py

Made by Zanteri

Feel free to email me any comments and feedback at [email protected]