def return_select_help_embed(author: discord.Member): embed = Embed( title='Select your character', description= '```\nSelect your character using which you will fight\n```\n Use to `dropdown` below to view the characters available and click the `confirm` button to confirm your character' ) embed.set_author(name=author.display_name, icon_url=author.display_avatar.url) return embed
async def callback(self, interaction: discord.Interaction): if self.view is None: raise AssertionError value = self.values[0] self.view.character = self.view.get_character_config(value) await interaction.response.defer() embed = Embed(title=self.view.character.name.title()) embed.set_image(url=random.choice(self.view.character.images)) embed.set_author(name=self.view.player.display_name, icon_url=self.view.player.display_avatar.url) await interaction.message.edit(embed=embed, view=self.view)
def make_embed( self, character: Optional[Characters] = None, author: Optional[discord.Member] = None, color: Optional[discord.Color] = None, ) -> Embed: character = character or (self.character1 if self.turn == self.player1 else self.character2) author = author or (self.player1 if character == self.character1 else self.player2) embed = Embed() embed.title = character.name embed.set_image(url=random.choice(character.images)) embed.set_footer( text= f'{self.special_moves1 if character == self.character1 else self.special_moves2} special moves left | {self.heal_moves1 if character == self.character1 else self.heal_moves2} heal operations left' ) embed.description = self.percentage_and_progess_bar( self.health1 if character == self.character1 else self.health2) embed.set_author(name=author.display_name, icon_url=author.display_avatar.url) if color is not None: embed.color = color return embed
async def create_giveaway(self, ctx: commands.Context): """Allowes you to to create giveaway by answering some simple questions!""" # Ask Questions embed = Embed( title="Giveaway Time!! \U00002728", description= "Time for a new Giveaway. Answer the following questions in 25 seconds each for the Giveaway", color=ctx.author.color, ) await ctx.send(embed=embed) questions = [ "In Which channel do you want to host the giveaway?", "For How long should the Giveaway be hosted ? type number followed (s|m|h|d)", "What is the Prize?", "What role should a person must have in order to enter? If no roles required then type `none`", "Tasks that the person should do in order to participate? If no tasks then type `none`", ] answers = [] def check(m): return m.author == ctx.author and m.channel == ctx.channel for i, question in enumerate(questions): embed = Embed(title=f"Question {i+1}", description=question) await ctx.send(embed=embed) try: message = await self.bot.wait_for("message", timeout=25, check=check) except TimeoutError: await ctx.send("You didn't answer the questions in Time") return answers.append(message.content) # Check if Channel Id is valid try: channel_id = int(answers[0][2:-1]) except: await ctx.send( f"The Channel provided was wrong. The channel provided should be like {ctx.channel.mention}" ) return channel = self.bot.get_channel(channel_id) # Check if the role is valid role = answers[3] if role.lower() in ("none", "no", "no roles"): role = None else: try: int(answers[3][3:-1]) except: i = ctx.guild.roles for j in i: if j.name in ("@everyone", "@here"): i.remove(j) bot_roles = choice(i) await ctx.send( f"The role provided was wrong. The role should be like {bot_roles.mention}" ) return time_ends = convert(answers[1]) * 1000 # Check if Time is valid if time == -1: await ctx.send("The Time format was wrong") return if time == -2: await ctx.send("The Time was not conventional number") return prize = answers[2] task = answers[4] if task.lower() in ("none", "no", "no task"): task = None embed = Embed( title="**:tada::tada: Giveaway Time !! :tada::tada:**", description=f":gift: Win a **{prize}** today", colour=0x00FFFF, ) embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.display_avatar.url) embed.set_image(url=self.giveaway_image) embed.add_field( name="Giveway ends in", value= f"{format_relative(discord.utils.utcnow() + timedelta(milliseconds=time_ends))} | [Timer]({LinksAndVars.website.value}/giveaway_timer.html?start={int(time.time() * 1000)}&length={time_ends})", ) if role: embed.add_field(name="Role Required", value=f"{role}") if task: embed.add_field(name="\U0001f3c1 Tasks", value=task) newMsg = await channel.send(embed=embed) embed.set_footer(text=f"Giveaway ID: {newMsg.id}") await newMsg.edit(embed=embed) await newMsg.add_reaction(discord.PartialEmoji(name="\U0001f389")) await ctx.send( f"Your giveaway will be hosted in {channel.mention} and will last for {answers[1]}\n{newMsg.jump_url}" ) await self.create_timer_for_giveaway( newMsg, (discord.utils.utcnow() + timedelta(milliseconds=time_ends)).timestamp())
async def determine_winner( self, giveaway_id: discord.Message, bot: commands.Bot) -> Union[str, discord.Member]: """Determines winner :param giveaway_id: The giveaway id :type giveaway_id: discord.Message :param bot: The bot class :type bot: commands.Bot :return: The winner details :rtype: Union[str, discord.Member] """ reactions = discord.utils.find( lambda a: str(a) == str(discord.PartialEmoji(name="\U0001f389")), giveaway_id.reactions) if reactions is None: return "The channel or ID mentioned was incorrect" try: giveaway_config = await self.get_giveaway_config( giveaway_id. id if not isinstance(giveaway_id.id, int) else giveaway_id) except AttributeError as e: return str(e) reacted_users = await reactions.users().flatten() if discord.utils.get(reacted_users, id=bot.application_id): reacted_users.remove( discord.utils.get(reacted_users, id=bot.application_id)) if giveaway_config.role_required is not None and len( reacted_users) <= 0: reacted_users = list( filter( lambda a: discord.utils.get( a.roles, id=int( giveaway_config.role_required.lstrip('<@&').lstrip( '<&').rstrip('>'))) is not None, reacted_users)) if len(reacted_users) <= 0: emptyEmbed = Embed( title= "\U0001f389\U0001f389 Giveaway Time !! \U0001f389\U0001f389", description="\U0001f381 Win a Prize today") emptyEmbed.set_author( name=giveaway_config.host.display_name, icon_url=giveaway_config.host.display_avatar.url) emptyEmbed.add_field( name="No winners", value="Not enough participants to determine the winners", ) emptyEmbed.set_image(url=self.giveaway_image) emptyEmbed.set_footer(text="No one won the Giveaway") await giveaway_id.edit(embed=emptyEmbed) return f"No one won the giveaway! As there were not enough participants!\n{giveaway_config.jump_url}" winner = choice(reacted_users) winnerEmbed = giveaway_config.embed if discord.utils.find( lambda a: a["name"].lower() == "\U0001f389 Winner \U0001f389". lower(), giveaway_config.embed_dict["fields"]) is None: winnerEmbed.add_field(name="\U0001f389 Winner \U0001f389", value=winner.mention, inline=False) await giveaway_id.edit(embed=winnerEmbed) return winner