SoulmateDoggy
Feb. 2024
Personal project
Want to Get a Dog? Let's Find a Dog to Be Our Soulmates!
This bot will find the right dog for you. Your choices from an emergency are truly the most genuine! Trust me!!
This is a project to create a Discord bot that recommends dogs, and we designed it to be fun while also functioning as an informant. I'm sure the bot will recommend you a breed of dog, but the reason can be a bit ridiculous.
< Discord, Phython >
This bot will find the right dog for you. Your choices from an emergency are truly the most genuine! Trust me!!
This is a project to create a Discord bot that recommends dogs, and we designed it to be fun while also functioning as an informant. I'm sure the bot will recommend you a breed of dog, but the reason can be a bit ridiculous.
< Discord, Phython >
Decision Tree
1. Write all the decision tree into code
In order to avoid confusion along the way, numbers were assigned to each node and organized. When writing answer and children, I was able to write quickly and accurately.
In addition, because the phrase to be put in the node contains ', the front and back of the node used "". This is because I used ' for contraction in the node context, when using ' in front and back of the node, python thinks that my node is finished in the middle of the context.
## 2. Create an Decision Tree
node24 = Node("Congrats, your partner is Greenland Dog! Greenland Dog is an arctic dog breed with thick winter hair and muscular build resistant to cold. You died of tetanus from a scar on your hand that was rummaging through the wreckage of an airplane. If the Greenland Dog, talented in tracking and hunting, were with you, you wouldn't die of tetanus." , answer='Check it')
node23 = Node("Congrats, your partner is a Siberian Husky! Siberian Husky is a breed of dog from the Arctic who can withstand the cold due to its thick winter fur and muscular build. After being rediscovered and killed by a polar bear while approaching too slowly, you need an Siberian Husky with good speed and agility. Follow your dog's example and move quickly." , answer='Approach slowly while looking around.')
.
.
.
node2 = Node("You were lucky to get stuck in a tree when you crashed on the plane. But you heard a sound under a tree. What is it?", answer='Polar regions',children=[node5, node6])
node1 = Node("You gave a lifeboat to the one who couldn't swim. What's your relationship with the one?", answer='Sea', children=[node3, node4])
root = Node('Where were you in distress?', children=[node1, node2])
node24 = Node("Congrats, your partner is Greenland Dog! Greenland Dog is an arctic dog breed with thick winter hair and muscular build resistant to cold. You died of tetanus from a scar on your hand that was rummaging through the wreckage of an airplane. If the Greenland Dog, talented in tracking and hunting, were with you, you wouldn't die of tetanus." , answer='Check it')
node23 = Node("Congrats, your partner is a Siberian Husky! Siberian Husky is a breed of dog from the Arctic who can withstand the cold due to its thick winter fur and muscular build. After being rediscovered and killed by a polar bear while approaching too slowly, you need an Siberian Husky with good speed and agility. Follow your dog's example and move quickly." , answer='Approach slowly while looking around.')
.
.
.
node2 = Node("You were lucky to get stuck in a tree when you crashed on the plane. But you heard a sound under a tree. What is it?", answer='Polar regions',children=[node5, node6])
node1 = Node("You gave a lifeboat to the one who couldn't swim. What's your relationship with the one?", answer='Sea', children=[node3, node4])
root = Node('Where were you in distress?', children=[node1, node2])
2. Add image to ‘Check your soulmate's look’ button
@discord.ui.button(label="Check your soulmate's look")
async def buttonCallback(self, interaction, button):
embed = discord.Embed(title="Your Best buddy",
description="I'm sure you found your soulmate",
color=0xffccfd)
embed.set_image(url="https://cdn.royalcanin-weshare-online.io/hz9p43oBRYZmsWpcq7ap/v1/bp-lot-1-labrador-couleur-outdoor")
embed.add_field(name="Congratulations, your mate is a Labrador Retriever!",
value="Labrador Retriever is friendly and swims well. However, Labrador Retriever only has the hunting ability to catch floating objects in the water, so you unfortunately died of starvation. Fortunately, thanks to the Labrador Retriever's affinity, your friend survived. Yay!",
inline=True)
await interaction.response.send_message(embed=embed)
I wanted to make the image link linked to each node appear when I press the button. So I embeded the image to @discord.ui.button's callback, but the result suddenly popped out of the wrong order.
async def buttonCallback(self, interaction, button):
embed = discord.Embed(title="Your Best buddy",
description="I'm sure you found your soulmate",
color=0xffccfd)
embed.set_image(url="https://cdn.royalcanin-weshare-online.io/hz9p43oBRYZmsWpcq7ap/v1/bp-lot-1-labrador-couleur-outdoor")
embed.add_field(name="Congratulations, your mate is a Labrador Retriever!",
value="Labrador Retriever is friendly and swims well. However, Labrador Retriever only has the hunting ability to catch floating objects in the water, so you unfortunately died of starvation. Fortunately, thanks to the Labrador Retriever's affinity, your friend survived. Yay!",
inline=True)
await interaction.response.send_message(embed=embed)
I wanted to make the image link linked to each node appear when I press the button. So I embeded the image to @discord.ui.button's callback, but the result suddenly popped out of the wrong order.
class WrongView(View):
def __init__(self, node):
super().__init__()
self.node = node
So when I read the code slowly, I found that part was stuck in a strange place. After I moved the code into the Wrongview class, which is only generated when the Leaf node was reached, it worked fine.
@discord.ui.button(label="Check your soulmate's look")
async def buttonCallback(self, interaction, button):
if self.node.value.startswith("Congratulations, your mate is a Labrador Retriever!"):
embed = discord.Embed(title="Your Best buddy",
description="I'm sure you found your soulmate",
color=0xffccfd)
embed.set_image(url="https://cdn.royalcanin-weshare-online.io/hz9p43oBRYZmsWpcq7ap/v1/bp-lot-1-labrador-couleur-outdoor")
embed.add_field(name="Congratulations, your mate is a Labrador Retriever!",
value="Labrador Retriever is friendly and swims well. However, Labrador Retriever only has the hunting ability to catch floating objects in the water, so you unfortunately died of starvation. Fortunately, thanks to the Labrador Retriever's affinity, your friend survived. Yay!",
inline=True)
await interaction.response.send_message(embed=embed)
And the code was written using the beginning sentence of each leaf so that each image was only visible in that leaf. Therefore, as you can see in the image next to you, the image is not visible unless it is a leaf starting with Congrats, your mate is a Labrador Retriever.
def __init__(self, node):
super().__init__()
self.node = node
So when I read the code slowly, I found that part was stuck in a strange place. After I moved the code into the Wrongview class, which is only generated when the Leaf node was reached, it worked fine.
@discord.ui.button(label="Check your soulmate's look")
async def buttonCallback(self, interaction, button):
if self.node.value.startswith("Congratulations, your mate is a Labrador Retriever!"):
embed = discord.Embed(title="Your Best buddy",
description="I'm sure you found your soulmate",
color=0xffccfd)
embed.set_image(url="https://cdn.royalcanin-weshare-online.io/hz9p43oBRYZmsWpcq7ap/v1/bp-lot-1-labrador-couleur-outdoor")
embed.add_field(name="Congratulations, your mate is a Labrador Retriever!",
value="Labrador Retriever is friendly and swims well. However, Labrador Retriever only has the hunting ability to catch floating objects in the water, so you unfortunately died of starvation. Fortunately, thanks to the Labrador Retriever's affinity, your friend survived. Yay!",
inline=True)
await interaction.response.send_message(embed=embed)
And the code was written using the beginning sentence of each leaf so that each image was only visible in that leaf. Therefore, as you can see in the image next to you, the image is not visible unless it is a leaf starting with Congrats, your mate is a Labrador Retriever.
3. Embed images for each leaf node
When the image of the second leaf node was embedded, the image of the first leaf node suddenly stopped coming out.
class WrongView(View):
def __init__(self, node):
super().__init__()
self.node = node
@discord.ui.button(label="Check your soulmate's look")
async def buttonCallback(self, interaction, button):
if self.node.value.startswith("Congratulations, your mate is a Labrador Retriever!"):
embed = discord.Embed(title="Your Best buddy",
description="I'm sure you found your soulmate",
color=0xffccfd)
embed.set_image(url="https://cdn.royalcanin-weshare-online.io/hz9p43oBRYZmsWpcq7ap/v1/bp-lot-1-labrador-couleur-outdoor")
embed.add_field(name="Congratulations, your mate is a Labrador Retriever!",
value="Labrador Retriever is friendly and swims well. However, Labrador Retriever only has the hunting ability to catch floating objects in the water, so you unfortunately died of starvation. Fortunately, thanks to the Labrador Retriever's affinity, your friend survived. Yay!",
inline=True)
if self.node.value.startswith("Congratulations, your mate is the Portuguese Water Dog!"):
embed=discord.Embed(title="Your Best buddy", url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg", description="I sure you found your soulmate", color=0xffccfd)
embed.set_author(name="Bot",
url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg", icon_url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg")
embed.set_thumbnail(url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg")
embed.add_field(name="Congratulations, your mate is the Portuguese Water Dog!",
value="The Portuguese Water Dog is friendly and swims well. It's also good at hunting, so hunting fish is gum! Although everyone died of starvation because of the lack of fire, it's a relief that we're not really drifting in the sea. Yay!",
inline=True)
class WrongView(View):
def __init__(self, node):
super().__init__()
self.node = node
@discord.ui.button(label="Check your soulmate's look")
async def buttonCallback(self, interaction, button):
if self.node.value.startswith("Congratulations, your mate is a Labrador Retriever!"):
embed = discord.Embed(title="Your Best buddy",
description="I'm sure you found your soulmate",
color=0xffccfd)
embed.set_image(url="https://cdn.royalcanin-weshare-online.io/hz9p43oBRYZmsWpcq7ap/v1/bp-lot-1-labrador-couleur-outdoor")
embed.add_field(name="Congratulations, your mate is a Labrador Retriever!",
value="Labrador Retriever is friendly and swims well. However, Labrador Retriever only has the hunting ability to catch floating objects in the water, so you unfortunately died of starvation. Fortunately, thanks to the Labrador Retriever's affinity, your friend survived. Yay!",
inline=True)
await interaction.response.send_message(embed=embed)
elif self.node.value.startswith("Congratulations, your mate is the Portuguese Water Dog!"):
embed=discord.Embed(title="Your Best buddy", url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg", description="I sure you found your soulmate", color=0xffccfd)
embed.set_thumbnail(url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg")
embed.add_field(name="Congratulations, your mate is the Portuguese Water Dog!",
value="The Portuguese Water Dog is friendly and swims well. It's also good at hunting, so hunting fish is gum! Although everyone died of starvation because of the lack of fire, it's a relief that we're not really drifting in the sea. Yay!",
inline=True)
await interaction.response.send_message(embed=embed)
The reason was that I used if again under if. I didn't know that the conditional statement after the if clause had to use elif. And it is also essential to include await interaction.response.send_message(embed=embed)
def __init__(self, node):
super().__init__()
self.node = node
@discord.ui.button(label="Check your soulmate's look")
async def buttonCallback(self, interaction, button):
if self.node.value.startswith("Congratulations, your mate is a Labrador Retriever!"):
embed = discord.Embed(title="Your Best buddy",
description="I'm sure you found your soulmate",
color=0xffccfd)
embed.set_image(url="https://cdn.royalcanin-weshare-online.io/hz9p43oBRYZmsWpcq7ap/v1/bp-lot-1-labrador-couleur-outdoor")
embed.add_field(name="Congratulations, your mate is a Labrador Retriever!",
value="Labrador Retriever is friendly and swims well. However, Labrador Retriever only has the hunting ability to catch floating objects in the water, so you unfortunately died of starvation. Fortunately, thanks to the Labrador Retriever's affinity, your friend survived. Yay!",
inline=True)
if self.node.value.startswith("Congratulations, your mate is the Portuguese Water Dog!"):
embed=discord.Embed(title="Your Best buddy", url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg", description="I sure you found your soulmate", color=0xffccfd)
embed.set_author(name="Bot",
url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg", icon_url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg")
embed.set_thumbnail(url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg")
embed.add_field(name="Congratulations, your mate is the Portuguese Water Dog!",
value="The Portuguese Water Dog is friendly and swims well. It's also good at hunting, so hunting fish is gum! Although everyone died of starvation because of the lack of fire, it's a relief that we're not really drifting in the sea. Yay!",
inline=True)
class WrongView(View):
def __init__(self, node):
super().__init__()
self.node = node
@discord.ui.button(label="Check your soulmate's look")
async def buttonCallback(self, interaction, button):
if self.node.value.startswith("Congratulations, your mate is a Labrador Retriever!"):
embed = discord.Embed(title="Your Best buddy",
description="I'm sure you found your soulmate",
color=0xffccfd)
embed.set_image(url="https://cdn.royalcanin-weshare-online.io/hz9p43oBRYZmsWpcq7ap/v1/bp-lot-1-labrador-couleur-outdoor")
embed.add_field(name="Congratulations, your mate is a Labrador Retriever!",
value="Labrador Retriever is friendly and swims well. However, Labrador Retriever only has the hunting ability to catch floating objects in the water, so you unfortunately died of starvation. Fortunately, thanks to the Labrador Retriever's affinity, your friend survived. Yay!",
inline=True)
await interaction.response.send_message(embed=embed)
elif self.node.value.startswith("Congratulations, your mate is the Portuguese Water Dog!"):
embed=discord.Embed(title="Your Best buddy", url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg", description="I sure you found your soulmate", color=0xffccfd)
embed.set_thumbnail(url="https://www.akc.org/wp-content/uploads/2017/11/Portuguese-Water-Dog-standing-in-profile-outdoors.jpg")
embed.add_field(name="Congratulations, your mate is the Portuguese Water Dog!",
value="The Portuguese Water Dog is friendly and swims well. It's also good at hunting, so hunting fish is gum! Although everyone died of starvation because of the lack of fire, it's a relief that we're not really drifting in the sea. Yay!",
inline=True)
await interaction.response.send_message(embed=embed)
The reason was that I used if again under if. I didn't know that the conditional statement after the if clause had to use elif. And it is also essential to include await interaction.response.send_message(embed=embed)