Hi everyone! I’m trying to improve my Discord bot and I want it to send messages in a cool-looking box format. I saw another bot that does this and it looks awesome.
The box has different colored sections:
- A yellow part that shows who suggested the command
- A light blue part with the actual command text
- A dark blue part that lists some roles
I’m not sure how to make my bot create messages like this. Is it possible to add these fancy boxes and color sections to bot messages? How would I go about coding this?
Here’s a basic example of what I’m trying to do:
@bot.command()
async def suggest(ctx, *, suggestion):
# How to create a fancy box message here?
await ctx.send(f'{ctx.author} suggested: {suggestion}')
@bot.command()
async def add_roles(ctx, member: discord.Member, *roles):
# Need help formatting this as a cool box message
for role in roles:
await member.add_roles(discord.utils.get(ctx.guild.roles, name=role))
Any tips on how to achieve this type of formatting would be super helpful. Thanks!
I’ve worked with Discord bots quite a bit, and for what you’re trying to achieve, Discord’s embed feature is indeed the way to go. It offers great flexibility for creating those eye-catching message boxes.
Here’s a more advanced approach you might consider:
def create_fancy_embed(author, content, roles=None):
embed = discord.Embed()
embed.set_author(name=f'Suggested by {author.name}', icon_url=author.avatar_url)
embed.description = content
embed.color = discord.Color.blue()
if roles:
embed.add_field(name='Roles', value=', '.join(roles), inline=False)
return embed
@bot.command()
async def suggest(ctx, *, suggestion):
embed = create_fancy_embed(ctx.author, suggestion)
await ctx.send(embed=embed)
@bot.command()
async def add_roles(ctx, member: discord.Member, *roles):
# Add roles logic here
embed = create_fancy_embed(ctx.author, f'Roles added to {member.mention}', roles)
await ctx.send(embed=embed)
This approach creates a reusable function for your embeds, making your code more maintainable and consistent across commands.
I’ve actually implemented something like this in one of my bots. The key is using Discord’s embed feature, which allows for those sleek, customizable message boxes.
For your suggest command, you can create an embed with different color sections like this:
embed = discord.Embed()
embed.add_field(name='Suggested by', value=ctx.author.mention, color=0xFFFF00)
embed.add_field(name='Suggestion', value=suggestion, color=0x87CEEB)
await ctx.send(embed=embed)
For the add_roles command, you could do:
embed = discord.Embed(title='Roles Added', color=0x000080)
role_list = ', '.join(roles)
embed.add_field(name='Member', value=member.mention)
embed.add_field(name='Roles', value=role_list)
await ctx.send(embed=embed)
You can adjust the colors using hex codes. Play around with it to get the exact look you want. Hope this helps!
hey man, i’ve done something similar before. you’ll wanna use discord’s embed feature for those fancy boxes. it lets u customize colors and add different sections.
for the suggest command, try something like:
embed = discord.Embed(title=‘Suggestion’, color=0x00ff00)
embed.add_field(name=‘Suggested by’, value=ctx.author.name, inline=False)
embed.add_field(name=‘Suggestion’, value=suggestion, inline=False)
await ctx.send(embed=embed)
hope that helps get u started!