pythondiscorddisnake

Basics - How do I output random.sample to newlines for a Discord bot?


My first time doing any coding, so apologies in advance.

I'm making a Discord bot for fun and am trying to get random.sample to output each selection to a new line.

Currently looks like this

Need it to look like:

Seed the Rebellion Wreck the Place Burn it Down

Code here:

import disnake
import random
from disnake.ext import commands
from variables import IntriguesList

class IntrigueCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot      
        
    @commands.slash_command(guild_ids= [guildID])
    async def intrigue(interaction: disnake.ApplicationCommandInteraction):
        """Generate Intrigues for an upcoming battle"""
        await interaction.response.defer(with_message=True)
        intrigue = disnake.Embed(
        title="Intrigues",
        description="Three side-missions for your next battle",
        color = disnake.Colour.dark_green()
        )
        
        intrigue.add_field(name="Your Intrigues", value=f"{(random.sample(IntriguesList, 3))}")

Tried \n in various ways, but don't really know what I'm doing so help greatly appreciated!


Solution

  • You can use \n to enter a newline.

    sample = random.sample(IntriguesList, 3)
    sample_str = "\n".join(sample)
    intrigue.add_field(name="Your Intrigues", value=sample_str)