Skip to content

Custom spawn messages

ContestedWheel edited this page May 6, 2025 · 11 revisions

Important

This tutorial is now archived because Ballsdex has made their own way to add custom spawn messages. If you want to ditch this method of adding custom spawn messages in favor of the official method, simply update your bot using git pull and then make sure to rebuild using docker compose build.


You may have seen some dexes that have one custom spawn message or even multiple spawn messages. In this tutorial, we will be adding custom spawn messages in our bot. You will have the options of either sticking to one custom spawn message or having multiple random ones.

One custom spawn message

  1. Go to ballsdex/packages/countryballs

You will see the following files:

image

  1. Open countryball.py in your text editor and scroll down until you see this part (or go to line 206):
        extension = self.model.wild_card.split(".")[-1]
        file_location = "./admin_panel/media/" + self.model.wild_card
        file_name = f"nt_{generate_random_name()}.{extension}"
        try:
            permissions = channel.permissions_for(channel.guild.me)
            if permissions.attach_files and permissions.send_messages:
                self.message = await channel.send(
                    f"A wild {settings.collectible_name} appeared!",
                    view=self,
                    file=discord.File(file_location, filename=file_name),
                )
                return True
            else:
                log.error("Missing permission to spawn ball in channel %s.", channel)
        except discord.Forbidden:
            log.error(f"Missing permission to spawn ball in channel {channel}.")
        except discord.HTTPException:
            log.error("Failed to spawn ball", exc_info=True)
        return False
  1. Change f"A wild {settings.collectible_name} appeared!", to anything of your choice.

Tip

Let's say if I wanna change my spawn message to say "A countryball to collect has appeared!", I will replace the line with f"A {settings.collectible_name} to collect has appeared!",

Keep {settings.collectible_name} if you want the spawn message to address it's a countryball.

Once you replace the line, it should look like this:

        extension = self.model.wild_card.split(".")[-1]
        file_location = "./admin_panel/media/" + self.model.wild_card
        file_name = f"nt_{generate_random_name()}.{extension}"
        try:
            permissions = channel.permissions_for(channel.guild.me)
            if permissions.attach_files and permissions.send_messages:
                self.message = await channel.send(
                    f"A {settings.collectible_name} to collect has appeared!",
                    view=self,
                    file=discord.File(file_location, filename=file_name),
                )
                return True
            else:
                log.error("Missing permission to spawn ball in channel %s.", channel)
        except discord.Forbidden:
            log.error(f"Missing permission to spawn ball in channel {channel}.")
        except discord.HTTPException:
            log.error("Failed to spawn ball", exc_info=True)
        return False
  1. Save the file by pressing CTRL + S on your keyboard or File > Save on your text editor, then close it.

  2. Restart the bot using docker compose restart. Once it's back up, make sure the message works by using /admin countryballs spawn to spawn a ball.

Important

If you get "An error occured when running the command. Contact support if this persists.", you most likely didn't replace the line correctly. Check this by opening countryball.py and look for any errors you have possibly made trying to replace the line.

Multiple spawn messages

This section will be a bit more on the advanced side.

  1. In the countryballs folder, create a new Text Document.

image

  1. Name the file spawnmsgs and change .txt to .py

A popup will ask if you are sure you want to change the file extension. Click "Yes" on this popup.

image

  1. Open the new file using your text editor. then copy and paste the following below into the file:
spawnmsglist = [
    "Wow",
    "Hello",
    "The french",
]

Important

If you want to add a new spawn message, look at the gif I made below to help you. Make sure you add a comma at the end of each spawn message you add, or you will get an error.

spawn

  1. Save the file by pressing CTRL + S on your keyboard or File > Save on your text editor, then close it.

  2. Open countryball.py and import the spawn message list by using this below:

from ballsdex.packages.countryballs.spawnmsgs import spawnmsglist

It should look like this:

from ballsdex.packages.countryballs.spawnmsgs import spawnmsglist
from ballsdex.settings import settings

if TYPE_CHECKING:
    from ballsdex.core.bot import BallsDexBot

log = logging.getLogger("ballsdex.packages.countryballs")

Then, scroll down to line 206 and replace f"A wild {settings.collectible_name} appeared!", with (random.choice(spawnmsglist)),

It should look like this:

        extension = self.model.wild_card.split(".")[-1]
        file_location = "./admin_panel/media/" + self.model.wild_card
        file_name = f"nt_{generate_random_name()}.{extension}"
        try:
            permissions = channel.permissions_for(channel.guild.me)
            if permissions.attach_files and permissions.send_messages:
                self.message = await channel.send(
                    (random.choice(spawnmsglist)),
                    view=self,
                    file=discord.File(file_location, filename=file_name),
                )
                return True
            else:
                log.error("Missing permission to spawn ball in channel %s.", channel)
        except discord.Forbidden:
            log.error(f"Missing permission to spawn ball in channel {channel}.")
        except discord.HTTPException:
            log.error("Failed to spawn ball", exc_info=True)
        return False
  1. Save the file by pressing CTRL + S on your keyboard or File > Save on your text editor, then close it.

  2. Restart the bot using docker compose restart. Once it's back up, make sure the spawn messages works by using /admin countryballs spawn to spawn a ball.

That is all for this tutorial. Once again, credits to porcelainscars for coding the multiple spawn messages.

Clone this wiki locally