async def kick(self, ctx: Context, member: Member, *, reason: str = "N/A") -> NoReturn: """Kicks the user. Attributes: ----------- - `member` - user - `reason` - kick reason """ s = await Settings(ctx.guild.id) lang = await s.get_field("locale", CONFIG["default_locale"]) STRINGS = Strings(lang) select_components = [[ Button(style=ButtonStyle.green, label="✓"), Button(style=ButtonStyle.red, label="X"), ]] done_components = [[ Button(style=ButtonStyle.grey, label="·", disabled=True), ]] embedconfirm = discord.Embed( title="Kick Command", description="```Do you want to kick this member?```", ) await ctx.send(embed=embedconfirm, components=select_components) response = await self.bot.wait_for( "button_click", check=lambda message: message.author == ctx.author) if response.component.label == "✓": await response.respond( type=7, embed=discord.Embed( title="Action Completed", description=f"Kicked {member} for {reason}", color=0xDD2E44, ), components=done_components, ) if not member.bot: embed = Utils.error_embed( STRINGS["moderation"]["dm_kick"].format(ctx.guild, reason)) await member.send(embed=embed) await asyncio.sleep(5) await member.kick() await ctx.message.add_reaction(CONFIG["yes_emoji"]) else: await response.respond( type=7, embed=discord.Embed( title="Action Aborted", description="The action was aborted by clicking the no button", color=0xDD2E44, ), components=done_components, ) return
async def get_ssp_buttons(ctx=None, message=None, disabled=False): if ctx: message = ctx.message buttons = [ [ Button( style=await get_buttoncolour(message), label="Schere", emoji="✂", custom_id="ssp_scissors", ), Button( style=await get_buttoncolour(message), label="Stein", emoji="🪨", custom_id="ssp_stone", ), Button( style=await get_buttoncolour(message), label="Papier", emoji="📄", custom_id="ssp_paper", ), ], ] if disabled: final_button_array, cache_array = [], [] for array in buttons: for button in array: button._disabled = True cache_array.append(button) final_button_array.append(cache_array) cache_array = [] return buttons
async def boolean_updater(self, ctx, settings_category: str, setting: str, ask_text: str): config = copy.deepcopy(self.bot.servers_config[str(ctx.guild.id)][settings_category]) options = [[Button(style=ButtonStyle.green, label="Yes", custom_id="yes"), Button(style=ButtonStyle.red, label="No", custom_id="no")]] msg = await ctx.send(content=ask_text, components=options) def check(res): return ctx.author == res.user and res.channel == ctx.channel try: resp = await self.bot.wait_for("button_click", check=check, timeout=60) await resp.respond(type=InteractionType.DeferredUpdateMessage) enable = resp.component.custom_id await msg.delete() if enable == "yes": self.bot.servers_config[str(ctx.guild.id)][settings_category][setting] = True set_v = True else: self.bot.servers_config[str(ctx.guild.id)][settings_category][setting] = False set_v = False self.bot.update_server_json() # await ctx.send("Set {} {} to {}".format(settings_category, setting, set_v)) await ctx.send(embed=self.updated_embed(ctx, settings_category, setting, config, self.bot.servers_config[str(ctx.guild.id)][settings_category])) except TimeoutError: await ctx.send(self.timeout_message) return
async def say(self, ctx: commands.Context, *, text): time = datetime.datetime.now() msg2 = ctx.message user = ctx.author.name if await botchannel_check(ctx): if await blacklist_check(self, ctx.message): return msg = await ctx.send( content=str(text), components=[[ Button( style=await get_buttoncolour(message=ctx.message), label="Normal", emoji="📄", id="say_normal", disabled=True, ), Button( style=await get_buttoncolour(message=ctx.message), label="Embed", emoji="✒", id="say_embed", ), ]], allowed_mentions=discord.AllowedMentions.none(), ) await save_message_to_cache(message=msg, author=msg2.author) await log( str(time) + ": Der Nutzer " + str(user) + " hat den Befehl " + await get_prefix_string(ctx.message) + "ssp benutzt!", guildid=ctx.guild.id, ) else: Bot.dispatch(self.bot, "botchannelcheck_failure", ctx)
async def game(self, ctx): DiscordComponents(self.bot) quote, name = self.get_random_quote() database = self.get_characters() component = self.create_random_components(database, name) question = await ctx.send(quote, components=[component]) try: interaction = await self.bot.wait_for("button_click", timeout=10) if interaction.component.label == name: await question.edit(quote, components=[ Button(style=ButtonStyle.green, label="Correct!", disabled=True) ]) await interaction.respond( type=InteractionType.ChannelMessageWithSource, content="Lucky") else: await question.edit(quote, components=[ Button(style=ButtonStyle.red, label="You're an idiot!", disabled=True) ]) await interaction.respond( type=InteractionType.ChannelMessageWithSource, content="so bad") except: await question.edit( components=[Button(label="Too slow!", disabled=True)])
async def wait_for_user(ctx, bot, msg: discord.Message, say_action_cancelled=True): def check(ms): return ms.channel == ctx.message.channel and ms.author == ctx.message.author yes = "Yes" no = "No" what_the_fuck = "" await msg.edit(components=[[ Button(label=yes, style=ButtonStyle.green, emoji='✔️'), Button(label=no, style=ButtonStyle.red, emoji='✖️'), Button(label=what_the_fuck, style=ButtonStyle.gray, emoji='🗑️') ]]) interaction = await bot.wait_for("button_click", check=check) await msg.edit(components=[]) reply = interaction.component.label if reply == yes: return True elif reply == no: if say_action_cancelled: await ctx.send(get_language_str(ctx.guild.id, 26)) return False else: return False
async def test(self, ctx, *, arg=None): ddb = DiscordComponents(self.bot) counter = 0 m = await ctx.send(f"{counter} Clicks", components=[ Button(style=ButtonStyle.randomColor(), label="Click Me!", id="1", emoji="👉") ]) while True: res = await ddb.wait_for_interact("button_click") if res.channel == ctx.message.channel: counter += 1 await m.edit(f"{counter} Clicks", components=[ Button(style=ButtonStyle.randomColor(), label="Click Me!", id="1", emoji="👉") ]) print(counter) await res.respond( type=InteractionType.ChannelMessageWithSource, content=f'{res.component.label} {counter}') res = await ddb.wait_for_interact("button_click")
async def shutdown(self, ctx: Context): # Команда для выключения бота s = await Settings(ctx.guild.id) lang = await s.get_field("locale", CONFIG["default_locale"]) STRINGS = Strings(lang) author = ctx.message.author valid_users = [ "540142383270985738", "573123021598883850", "584377789969596416", "106451437839499264", "237984877604110336", "579750505736044574", "497406228364787717", "353049432037523467", "717822288375971900", "168422909482762240", ] select_components = [ Button(style=ButtonStyle.green, label="✓"), Button(style=ButtonStyle.red, label="X"), ] done_components = [ Button(style=ButtonStyle.grey, label="·", disabled=True) ] embedconfirm = discord.Embed( title=STRINGS["moderation"]["shutdownembedtitle"], description=STRINGS["moderation"]["shutdownconfirm"], ) await ctx.send(embed=embedconfirm, components=select_components) response = await self.bot.wait_for( "button_click", check=lambda message: message.author == ctx.author) if str(author.id) in valid_users and response.component.label == "✓": await response.respond( type=7, embed=discord.Embed( title=STRINGS["moderation"]["shutdownembedtitle"], description=STRINGS["moderation"]["shutdownembeddesc"], color=0xFF8000, ), components=done_components, ) await ctx.bot.change_presence(activity=discord.Game( name="Shutting down for either reboot or update ")) await asyncio.sleep(5) print("---------------------------") print("[SHUTDOWN] Shutdown requested by bot owner") print("---------------------------") await ctx.bot.close() else: await response.respond( type=7, embed=discord.Embed( title=STRINGS["moderation"]["shutdownaborttitle"], description=STRINGS["moderation"]["shutdownabortdesc"], color=0xDD2E44, ), components=done_components, )
async def test(ctx): await ctx.send("Przyciski", components=[Button(style=ButtonStyle.blue, label="test1", disabled=True), Button(style=ButtonStyle.red, label="test2")]) res = await bot.wait_for("button_click") await res.respond( type=InteractionType.ChannelMessageWithSource, content=res.component.label )
async def menu(self, ctx): menu_loop = True while menu_loop: settings_buttons = [] settings = list(ctx.command.cog.get_commands()[0].commands) settings.sort(key=lambda x: x.name) for setting in settings: if setting.name in ["show", "jsonset", "menu", "jsonshow"]: continue else: settings_buttons.append(Button(style=ButtonStyle.green, custom_id=setting.name, label=str(setting.name).capitalize())) def check(res): return ctx.author == res.user and res.channel == ctx.channel main_menu = await ctx.send("Select a settings type to change (60s timeout)", components=[settings_buttons]) try: resp = await self.bot.wait_for("button_click", check=check, timeout=60) await resp.respond(type=InteractionType.DeferredUpdateMessage) sub_menu_type = resp.component.custom_id except TimeoutError: await main_menu.delete() await ctx.send(self.timeout_message) return sub_settings = None for setting in settings: if setting.name == sub_menu_type: sub_settings = list(setting.commands) sub_settings.sort(key=lambda x: x.name) sub_settings_buttons = [] for sub_setting in sub_settings: sub_settings_buttons.append(Button(style=ButtonStyle.green, custom_id=sub_setting.name, label=str(sub_setting.name).capitalize())) await main_menu.edit("Select {} Sub Setting (60s timeout)".format(sub_menu_type), components=[sub_settings_buttons]) try: resp = await self.bot.wait_for("button_click", check=check, timeout=60) await resp.respond(type=InteractionType.DeferredUpdateMessage) cmd = resp.component.custom_id await main_menu.delete() except TimeoutError: await main_menu.delete() await ctx.send(self.timeout_message) return for sub_setting in sub_settings: if sub_setting.name == cmd: await sub_setting.__call__(ctx) menu_loop = await self.continue_checker(ctx, "Continue editing server configuration? (60s timeout)")
def create_components(character_move): tags = character_move["Tags"] components = [] for tag in tags: if tag == "Rage Art" or tag == "Rage Drive": components.append(Button(label=tag, disabled=True, style=4)) else: components.append(Button(label=tag, disabled=True, style=3)) components.sort(key=lambda val: const.SORT_ORDER[val.label]) return components
def components(inactive=False, deleted=False): return [[ Button(label="Deactivate", style=ButtonStyle.grey, id="deactivate", disabled=inactive or not incident_["active"]), Button(label="DELETE", style=ButtonStyle.red, id="delete", disabled=deleted) ]]
def components(current_page): return [[ Button(label="Previous", style=ButtonStyle.blue, emoji="◀", disabled=(current_page == 0)), Button(label="Next", style=ButtonStyle.blue, emoji="▶", disabled=(current_page == last_page)) ]]
async def purge(self, ctx: Context, number: int) -> NoReturn: """Deletes a specified number of messages in the current channel. Attributes: ----------- - `number` - The number of messages to be deleted. """ s = await Settings(ctx.guild.id) lang = await s.get_field("locale", CONFIG["default_locale"]) STRINGS = Strings(lang) select_components = [[ Button(style=ButtonStyle.green, label="✓"), Button(style=ButtonStyle.red, label="X"), ]] done_components = [[ Button(style=ButtonStyle.grey, label="·", disabled=True), ]] embedconfirm = discord.Embed( title="Clear Command", description=f"```Do you want to remove {number} messages?```", ) await ctx.send(embed=embedconfirm, components=select_components) response = await self.bot.wait_for( "button_click", check=lambda message: message.author == ctx.author) if response.component.label == "✓": await response.respond( type=7, embed=discord.Embed( title="Action Completed", description=f"Purging {number} messages", color=0xDD2E44, ), components=done_components, ) await asyncio.sleep(10) deleted = await ctx.channel.purge(limit=number + 1) else: await response.respond( type=7, embed=discord.Embed( title="Action Aborted", description="The action was aborted by clicking the no button", color=0xDD2E44, ), components=done_components, ) return
async def upvote(self, ctx): await ctx.send( "**Thnx For Voting in Advance**", components=[[ Button( style=ButtonStyle.URL, label="UpVote on DBL", url="https://discordbotlist.com/bots/hellothere/upvote"), Button(style=ButtonStyle.URL, label="UpVote on Top.gg", url="https://top.gg/bot/790592850588336151/vote"), ]])
async def infos(self, ctx): integrer = "1911946966" m = await ctx.send("Menu", buttons=[Button(style=ButtonStyle.URL, label="Invito", url=f"https://discord.com/api/oauth2/authorize?client_id={self.bot.user.id}&permissions={integrer}&scope=bot"), Button(style=ButtonStyle.green, label="Bot"), Button(style=ButtonStyle.URL, label="Sito ufficiale", url="https://responder.starnumber.tk"), Button(style=ButtonStyle.URL, label="Vota", url="https://top.gg/bot/725342148488069160/vote")]) res = await self.bot.wait_for("button_click") if not res.channel == ctx.channel: return False if res.component.value == "Bot": await res.respond( type=InteractionType.ChannelMessageWithSource, content=f'Questo bot è stato creato da StarNumber12046. E\'un piccolo bot italiano. Ecco alcune informazioni\nPing: {self.bot.latency * 1000}\nServers: {len(self.bot.guilds)}\nUtenti: {len(self.bot.users)}' )
async def button(ctx): await ctx.send(" ", components=[Button(label="Нажми на меня")]) interaction = await bot.wait_for("button_click") await interaction.respond(content="Поздравляю, ваша мать была выебана!")
def course_buttons(course_list): buttons_list = [] for course in course_list: # print(course) dep, num = course.split() buttons_list.append(Button(style=2, label="c!get " + dep + " " + num)) return buttons_list
async def yt(ctx): try: channel = ctx.author.voice.channel url = f"https://discord.com/api/v9/channels/{channel.id}/invites" params = { 'max_age': 86400, 'max_uses': 0, 'target_application_id': '755600276941176913', 'target_type': 2, 'temporary': False, 'validate': None } headers = { 'content-type': 'application/json', 'Authorization': f"Bot {os.getenv('DISCORD_TOKEN')}" } r = requests.post(url, data=json.dumps(params), headers=headers) link = f"https://discord.com/invite/{r.json()['code']}" await ctx.send("Click the button join Youtube Together in VC", components=[ Button(style=ButtonStyle.URL, label="Youtube Together", url=link), ]) except AttributeError: await ctx.send("You Are not in a VC") except: await ctx.send( "There is some error in starting Youtube Togther or I don't have permission to create invite in that channel" )
async def on_ready(self): """ When the bot has loading all components and extensions. """ # Initialize discord components DiscordComponents(bot=self) # Changing the current bot status self.logger.info( f'Successfully logged in as {self.user}\nSharded to {len(self.guilds)} guilds' ) await self.change_presence(activity=discord.Game( name='Use the prefix "M."')) # Load our extensions to register commands in each specific sector for ext in initial_cogs: self.load_extension(ext) self.logger.info("All extensions have loaded!") # Send a new verification message on every reinstation of the bot embed = self.em(title="Verification", description="This is to make sure you are not a bot!", color=0x00ff00) button = Button(label="Verify") channel = self.get_channel(int(VERIFICATION_CHANNEL)) return await channel.send(embed=embed, components=[button])
async def invite(self, ctx): time = datetime.datetime.now() user = ctx.author.name if await botchannel_check(ctx): embed = discord.Embed( title="**Invite**", color=await get_embedcolour(ctx.message) ) embed._footer = await get_embed_footer(ctx) embed._thumbnail = await get_embed_thumbnail() embed.add_field( name="**Link**", value=INVITE_LINK, ) await ctx.send( embed=embed, components=[ [ Button( style=ButtonStyle.URL, label="Klicke hier um mich zu einem Server hinzuzufügen!", url=INVITE_LINK, ), Button( style=ButtonStyle.URL, label="Discord", url=DISCORD_LINK, ), Button( style=ButtonStyle.URL, label="Website", url=WEBSITE_LINK, ), ] ], ) await log( str(time) + ": Der Nutzer " + str(user) + " hat den Befehl " + await get_prefix_string(ctx.message) + "invite benutzt!", ctx.guild.id, ) else: Bot.dispatch(self.bot, "botchannelcheck_failure", ctx)
async def invite(ctx): inv_button = Button( url= 'https://discord.com/oauth2/authorize?client_id=926198736907034624&permissions=509952&scope=bot', label='Click Me 🤖', style=5) await ctx.send('Invite Link:', components=[inv_button])
async def button(self, ctx): await ctx.send("Look! A cool Button", components=[Button(label="WOW button!")]) interaction = await self.bot.wait_for( "button_click", check=lambda i: i.component.label.startswith("WOW")) await interaction.respond(content="Button clicked!")
def components(): return [[ Button(label="<<", disabled=index == 0, style=ButtonStyle.blue, id="first"), Button(label="<", disabled=index == 0, style=ButtonStyle.blue, id="previous"), Button(label=">", disabled=index == pages - 1, style=ButtonStyle.blue, id="next"), Button(label=">>", disabled=index == pages - 1, style=ButtonStyle.blue, id="last") ], [ Button(label="Active", disabled=active, style=ButtonStyle.green, id="active"), Button(label="Inactive", disabled=not active, style=ButtonStyle.red, id="inactive") ], [ Button(label="Show notes", style=ButtonStyle.grey, disabled=notes, id="notes") ]]
def components(): return [[ Button(label="<<", disabled=index == 0, style=ButtonStyle.blue, id="first"), Button(label="<", disabled=index == 0, style=ButtonStyle.blue, id="previous"), Button(label=">", disabled=index == page_count - 1, style=ButtonStyle.blue, id="next"), Button(label=">>", disabled=index == page_count - 1, style=ButtonStyle.blue, id="last") ]]
def make_components(clicks: int, machines: List[str]) -> List[Component]: current_inventory = calculate_current_inventory(clicks, machines) components = [ self.bot.components_manager.add_callback( Button(emoji="📎", label="Zrób spinacz"), make_paperclip), ] if machines or current_inventory >= MACHINE_COST: components.append( self.bot.components_manager.add_callback( Button( emoji="🛠", label= "Kup maszynę spinaczotworzącą (20 spinaczy)", disabled=current_inventory < MACHINE_COST, ), buy_paperclip_machine, )) return components
async def rps(self, ctx): rock = "Ъфе" paper = "ЪЊ░" scissors = "Рюѓ№ИЈ" rps = [rock, paper, scissors] msg = await ctx.send( 'Pick your choice', components=[[Button(label=object) for object in rps]]) interaction = await self.bot.wait_for( "button_click", check=lambda i: i.user.id == ctx.author.id) try: reaction = interaction.component.label await msg.edit(components=[[ Button(style=ButtonStyle.green, label=reaction, disabled=True) if object == reaction else Button(label=object, disabled=True) for object in rps ]]) await interaction.respond(type=6) oppn_choice = choice(rps) if reaction == oppn_choice: await ctx.send("You both drew") if oppn_choice == rock: if reaction == scissors: await ctx.send("You lose!") if reaction == paper: await ctx.send("You win!") if oppn_choice == paper: if reaction == rock: await ctx.send("You lose!") if reaction == scissors: await ctx.send("You win!") if oppn_choice == scissors: if reaction == paper: await ctx.send("You lose!") if reaction == rock: await ctx.send("You win!") await ctx.send(f"The opponent chose {oppn_choice}") except TimeoutError: await ctx.send("No response was sent in time")
async def simp(self, ctx): m = await ctx.send("```glsl\nYou:- Hi\nMe:-\n```", components=[[ Button(style=ButtonStyle.red, label="Do You love Me ??", emoji="💗", disabled=True), Button( style=ButtonStyle.green, label="Yes I Do", ), ]]) def check(res): return ctx.author == res.user and res.channel == ctx.channel try: await self.bot.wait_for("button_click", check=check, timeout=5) await m.edit("Bahahahahhahah", components=[[ Button(style=ButtonStyle.blue, label="F Off", emoji="🤣", disabled=True), Button(style=ButtonStyle.red, label="You simp", emoji="💢", disabled=True), ]]) except asyncio.TimeoutError: await m.edit("You Better Reply Faster", components=[ Button(style=ButtonStyle.red, label="I Have Got Standards", disabled=True, emoji="😏"), ])
async def update_now_playing(self, channel): """ Deletes previous playing status embed and sends a new one. """ if not channel: return None webhook = await self.find_or_create_webhook(channel) if webhook: self.now_playing = await webhook.send( embed=self.np_embed(self.current, webhook=True), avatar_url=utils.get_user_avatar_url(channel.guild.me), username=self.np_status_str(self.current)) else: await self.update_last_playing() if 'components' in self.config.get('enabled_experiments', []): from discord_components import (DiscordComponents, Button, ButtonStyle) ddb: DiscordComponents = self.kwargs.get("ddb") if ddb: self.now_playing = await ddb.send_component_msg( channel, content="Buttons experiment enabled", embed=self.np_embed(self.current), components=[[ Button( label="\u275A\u275A" if self.vclient.is_playing() else "\u25B6\uFE0E", id="play-pause"), Button(label="\u2B1B\uFE0E", id="stop"), Button(label="\u25BA\u2759", id="skip"), Button(label="\U0001f501\uFE0E", id="repeat", style=ButtonStyle.blue if self.repeat else ButtonStyle.gray) ]]) self.now_playing.__dict__["has_component"] = True return self.now_playing = await channel.send( embed=self.np_embed(self.current))
async def continue_checker(self, ctx, ask_continue_text: str): options = [[Button(style=ButtonStyle.green, label="Yes", custom_id="yes"), Button(style=ButtonStyle.red, label="No", custom_id="no")]] msg = await ctx.send(content=ask_continue_text, components=options) def check(res): return ctx.author == res.user and res.channel == ctx.channel try: resp = await self.bot.wait_for("button_click", check=check, timeout=60) await resp.respond(type=InteractionType.DeferredUpdateMessage) enable = resp.component.custom_id await msg.delete() if enable == "yes": return True else: return False except TimeoutError: await ctx.send(self.timeout_message) return False