├── PatrickHand-Regular.ttf ├── asyncio ├── dog.jpg ├── gifs.json ├── part1.py ├── part10.py ├── part11.py ├── part12.py ├── part13.py ├── part14.py ├── part2.py ├── part3.py ├── part4.py ├── part5.py ├── part6.py ├── part9.py └── textwrap /PatrickHand-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dannycademy/nextcord-bot-series/118837f1ce1b02bad3db5b3c0b5aad25526142ff/PatrickHand-Regular.ttf -------------------------------------------------------------------------------- /asyncio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dannycademy/nextcord-bot-series/118837f1ce1b02bad3db5b3c0b5aad25526142ff/asyncio -------------------------------------------------------------------------------- /dog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dannycademy/nextcord-bot-series/118837f1ce1b02bad3db5b3c0b5aad25526142ff/dog.jpg -------------------------------------------------------------------------------- /gifs.json: -------------------------------------------------------------------------------- 1 | { 2 | "gif": [ 3 | "https://tenor.com/view/dogs-cute-all-you-need-is-love-gif-13111410", 4 | "https://tenor.com/view/puppy-high-five-cute-fluffy-gif-10903022", 5 | "https://media.discordapp.net/attachments/730945069711884289/808982584280350730/image0.gif", 6 | "https://tenor.com/view/puppies-silly-puppy-cute-puppy-doggys-dogs-gif-17639683", 7 | "https://tenor.com/view/golden-retriever-dog-did-you-call-me-mirame-perrito-golden-gif-17047579", 8 | "https://tenor.com/view/bedtime-sleepy-good-night-sleep-well-go-to-bed-gif-15801983", 9 | "https://tenor.com/view/look-puppy-hi-hello-gif-5047026", 10 | "https://tenor.com/view/dog-getting-frustrated-stop-it-annoyed-gif-15192974" 11 | ], 12 | "play": [ 13 | "https://tenor.com/view/animals-funny-dog-puppy-play-gif-3472074", 14 | "https://tenor.com/view/dogs-doggy-puppy-dog-playing-silly-gif-18588408", 15 | "https://tenor.com/view/cat-catur-mitokman-gif-20843952" 16 | ], 17 | "feed": [ 18 | "https://tenor.com/view/misti-german-shepherd-alsatian-dog-hungry-dog-gif-17711962", 19 | "https://tenor.com/view/funny-animals-dogs-eating-dinner-formal-dinner-gif-10400593", 20 | "https://tenor.com/view/nom-dog-dog-food-eating-gif-3315865", 21 | "https://tenor.com/view/doggo-good-gamer-mcdonalds-puppy-gif-14662701" 22 | ], 23 | "sleep": [ 24 | "https://tenor.com/view/golden-retriever-sleep-yawn-dog-puppy-gif-16433231", 25 | "https://tenor.com/view/hiding-under-covers-tired-sleepy-hiding-under-blanket-good-night-gif-13568050", 26 | "https://tenor.com/view/dog-tired-sad-depressed-exhausted-gif-18089551", 27 | "https://tenor.com/view/read-book-sleepy-boring-sleep-gif-13660152" 28 | ] 29 | } -------------------------------------------------------------------------------- /part1.py: -------------------------------------------------------------------------------- 1 | """new code""" 2 | from nextcord.ext import commands 3 | 4 | bot = commands.Bot(command_prefix = '!') 5 | 6 | @bot.command(name="hi") 7 | async def SendMessage(ctx): 8 | await ctx.send('Hello!') 9 | 10 | @bot.event 11 | async def on_ready(): 12 | print(f'\n\nLogged in as: {bot.user.name} - {bot.user.id}') 13 | 14 | if __name__ == '__main__': 15 | bot.run("PASTE YOUR TOKEN HERE") 16 | 17 | """new code""" -------------------------------------------------------------------------------- /part10.py: -------------------------------------------------------------------------------- 1 | from distutils.log import debug 2 | from matplotlib.pyplot import text 3 | from nextcord.ext import commands 4 | from pathvalidate import validate_symbol 5 | import requests, json, random, datetime, asyncio 6 | from PIL import Image, ImageFont, ImageDraw 7 | import textwrap 8 | from nextcord import File, ButtonStyle, Embed, Color, SelectOption 9 | from nextcord.ui import Button, View, Select 10 | 11 | links = json.load(open("gifs.json")) 12 | helpGuide = json.load(open("help.json")) 13 | 14 | bot = commands.Bot(command_prefix="dog ") 15 | bot.remove_command("help") 16 | 17 | # create help embed using page number and helpGuide 18 | def createHelpEmbed(pageNum=0, inline=False): 19 | pageNum = (pageNum) % len(list(helpGuide)) 20 | pageTitle = list(helpGuide)[pageNum] 21 | embed=Embed(color=0x0080ff, title=pageTitle) 22 | for key, val in helpGuide[pageTitle].items(): 23 | embed.add_field(name=bot.command_prefix+key, value=val, inline=inline) 24 | embed.set_footer(text=f"Page {pageNum+1} of {len(list(helpGuide))}") 25 | return embed 26 | 27 | 28 | @bot.command(name="help") 29 | async def Help(ctx): 30 | currentPage = 0 31 | 32 | # functionality for buttons 33 | 34 | async def next_callback(interaction): 35 | nonlocal currentPage, sent_msg 36 | currentPage += 1 37 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 38 | 39 | async def previous_callback(interaction): 40 | nonlocal currentPage, sent_msg 41 | currentPage -= 1 42 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 43 | 44 | 45 | 46 | # add buttons to embed 47 | 48 | previousButton = Button(label="<", style=ButtonStyle.blurple) 49 | nextButton = Button(label=">", style=ButtonStyle.blurple) 50 | previousButton.callback = previous_callback 51 | nextButton.callback = next_callback 52 | 53 | myview = View(timeout=180) 54 | myview.add_item(previousButton) 55 | myview.add_item(nextButton) 56 | 57 | sent_msg = await ctx.send(embed=createHelpEmbed(currentPage), view=myview) 58 | 59 | 60 | # @bot.command(name="help") 61 | # async def Help(ctx): 62 | # embed=Embed(color=0x0080ff, title="Basic Commands") 63 | # embed.add_field(name="dog pic", value="get a cute doggo pic :)", inline=False) 64 | # embed.add_field(name="dog gif", value="get a cute doggo gif :)", inline=False) 65 | # embed.add_field(name="dog play", value="get a cute playing doggo gif :)", inline=False) 66 | # embed.add_field(name="dog sleep", value="get a cute sleepy doggo gif :)", inline=False) 67 | # await ctx.send(embed=embed) 68 | 69 | 70 | 71 | 72 | # https://nextcord.readthedocs.io/en/latest/ext/commands/api.html#nextcord.ext.commands.cooldown 73 | @commands.cooldown(1, 2, commands.BucketType.user) 74 | @bot.command(name="hi") 75 | async def SendMessage(ctx): 76 | 77 | async def dropdown_callback(interaction): 78 | for value in dropdown.values: 79 | await ctx.send(random.choice(links[value])) 80 | 81 | option1 = SelectOption(label="chill", value="gif", description="doggo is lonely", emoji="😎") 82 | option2 = SelectOption(label="play", value="play", description="doggo is bored", emoji="🙂") 83 | option3 = SelectOption(label="feed", value="feed", description="doggo is hungry", emoji="😋") 84 | dropdown = Select(placeholder="What would you like to do with doggo?", options=[option1, option2, option3], max_values=3) 85 | dropdown.callback = dropdown_callback 86 | myview = View(timeout=180) 87 | myview.add_item(dropdown) 88 | 89 | await ctx.send('Hello! Are you bored?', view=myview) 90 | 91 | @commands.cooldown(1, 3, commands.BucketType.user) 92 | @bot.command(name="pic") 93 | async def Dog(ctx): 94 | response = requests.get("https://dog.ceo/api/breeds/image/random") 95 | image_link = response.json()["message"] 96 | await ctx.send(image_link) 97 | 98 | @commands.cooldown(1, 3, commands.BucketType.user) 99 | @bot.command(name="gif", aliases=["feed", "play", "sleep"]) 100 | async def Gif(ctx): 101 | await ctx.send(random.choice(links[ctx.invoked_with])) 102 | 103 | 104 | async def schedule_daily_message(h, m, s, msg, channelid): 105 | while True: 106 | now = datetime.datetime.now() 107 | # then = now+datetime.timedelta(days=1) 108 | then = now.replace(hour=h, minute=m, second=s) 109 | if then < now: 110 | then += datetime.timedelta(days=1) 111 | wait_time = (then-now).total_seconds() 112 | await asyncio.sleep(wait_time) 113 | 114 | channel = bot.get_channel(channelid) 115 | 116 | await channel.send(msg) 117 | await channel.send(random.choice(links["play"])) 118 | await asyncio.sleep(1) 119 | 120 | # dog daily "good morning" 8 30 121 | 122 | @commands.cooldown(1, 20, commands.BucketType.user) 123 | @bot.command(name="daily") 124 | async def daily(ctx, mystr:str, hour:int, minute:int, second:int): 125 | print(mystr, hour, minute, second) 126 | 127 | if not (0 < hour < 24 and 0 <= minute <= 60 and 0 <= second < 60): 128 | raise commands.BadArgument() 129 | 130 | time = datetime.time(hour, minute, second) 131 | timestr = time.strftime("%I:%M:%S %p") 132 | await ctx.send(f"A daily message will be sent at {timestr} everyday in this channel.\nDaily message:\"{mystr}\"\nConfirm by simply saying: `yes`") 133 | 134 | @daily.error 135 | async def daily_error(ctx, error): 136 | if isinstance(error, commands.BadArgument): 137 | await ctx.send("""Incorrect format. Use the command this way: `dog daily "message" hour minute second`. 138 | For example: `dog daily "good morning" 22 30 0` for a message to be sent at 10:30 everyday""") 139 | 140 | # dog speak hello world!! 141 | 142 | # @bot.command(name='hi') 143 | # async def hi(ctx, *args): 144 | 145 | # hi = Button(style=ButtonStyle.primary, label="hi") 146 | # bye = Button(style=ButtonStyle.danger, label="bye") 147 | # sub = Button(style=ButtonStyle.primary, label="sub!!", url="https://www.youtube.com/channel/UCqRLiT8Kv5RVmoNtnshKZwA?sub_confirmation=1") 148 | 149 | 150 | # async def hi_callback(interaction): 151 | # await interaction.response.send_message("Hello!!") 152 | # async def bye_callback(interaction): 153 | # await interaction.response.send_message("Bye :(") 154 | 155 | # hi.callback = hi_callback 156 | # bye.callback = bye_callback 157 | 158 | # myview = View(timeout=180) 159 | # for interaction in [sub, hi, bye]: 160 | # myview.add_item(interaction) 161 | 162 | # await ctx.send(f"hi {ctx.message.author.mention}", view=myview) 163 | 164 | 165 | @bot.command(name='support') 166 | async def support(ctx, *args): 167 | hi = Button(label="click me", style=ButtonStyle.blurple) 168 | 169 | async def hi_callback(interaction): 170 | await interaction.response.send_message("Hello!!") 171 | 172 | hi.callback = hi_callback 173 | 174 | myview = View(timeout=180) 175 | myview.add_item(hi) 176 | 177 | await ctx.send(f"hi {ctx.message.author.mention}", view=myview) 178 | 179 | @commands.cooldown(1, 5, commands.BucketType.user) 180 | @bot.command(name='speak') 181 | async def speak(ctx, *args): 182 | msg = " ".join(args) 183 | font = ImageFont.truetype("PatrickHand-Regular.ttf", 50) 184 | img = Image.open("dog.jpg") 185 | cx, cy = (350, 230) 186 | 187 | lines = textwrap.wrap(msg, width=20) 188 | print(lines) 189 | w, h = font.getsize(msg) 190 | y_offset = (len(lines)*h)/2 191 | y_text = cy-(h/2) - y_offset 192 | 193 | for line in lines: 194 | draw = ImageDraw.Draw(img) 195 | w, h = font.getsize(line) 196 | draw.text((cx-(w/2), y_text), line, (0, 0, 0), font=font) 197 | img.save("dog-edited.jpg") 198 | y_text += h 199 | 200 | with open("dog-edited.jpg", "rb") as f: 201 | img = File(f) 202 | await ctx.channel.send(file=img) 203 | 204 | 205 | @bot.event 206 | async def on_command_error(ctx, error): 207 | if isinstance(error, commands.CommandOnCooldown): 208 | em = Embed(title=f"Slow it down bro!",description=f"Try again in {error.retry_after:.2f}s.", color=Color.red()) 209 | await ctx.send(embed=em) 210 | else: 211 | print(error) 212 | 213 | @bot.event 214 | async def on_ready(): 215 | print(f"Loggined in as: {bot.user.name}") 216 | # await schedule_daily_message() 217 | 218 | if __name__ == '__main__': 219 | bot.run("PASTE YOUR TOKEN HERE") -------------------------------------------------------------------------------- /part11.py: -------------------------------------------------------------------------------- 1 | from distutils.log import debug 2 | from matplotlib.pyplot import text 3 | from nextcord.ext import commands 4 | from pathvalidate import validate_symbol 5 | import requests, json, random, datetime, asyncio 6 | from PIL import Image, ImageFont, ImageDraw 7 | import textwrap 8 | from nextcord import File, ButtonStyle, Embed, Color, SelectOption, Intents, Interaction, SlashOption 9 | from nextcord.ui import Button, View, Select 10 | 11 | # pip install nextcord --upgrade 12 | # reinvite bot with bot AND application.commands perm 13 | # https://docs.nextcord.dev/en/stable/interactions.html 14 | 15 | links = json.load(open("gifs.json")) 16 | helpGuide = json.load(open("help.json")) 17 | 18 | intents = Intents.default() 19 | intents.message_content = True 20 | bot = commands.Bot(command_prefix="dog ", intents=intents) 21 | bot.remove_command("help") 22 | 23 | # create help embed using page number and helpGuide 24 | def createHelpEmbed(pageNum=0, inline=False): 25 | pageNum = (pageNum) % len(list(helpGuide)) 26 | pageTitle = list(helpGuide)[pageNum] 27 | embed=Embed(color=0x0080ff, title=pageTitle) 28 | for key, val in helpGuide[pageTitle].items(): 29 | embed.add_field(name=bot.command_prefix+key, value=val, inline=inline) 30 | embed.set_footer(text=f"Page {pageNum+1} of {len(list(helpGuide))}") 31 | return embed 32 | 33 | 34 | @bot.command(name="help") 35 | async def Help(ctx): 36 | currentPage = 0 37 | 38 | # functionality for buttons 39 | 40 | async def next_callback(interaction): 41 | nonlocal currentPage, sent_msg 42 | currentPage += 1 43 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 44 | 45 | async def previous_callback(interaction): 46 | nonlocal currentPage, sent_msg 47 | currentPage -= 1 48 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 49 | 50 | 51 | 52 | # add buttons to embed 53 | 54 | previousButton = Button(label="<", style=ButtonStyle.blurple) 55 | nextButton = Button(label=">", style=ButtonStyle.blurple) 56 | previousButton.callback = previous_callback 57 | nextButton.callback = next_callback 58 | 59 | myview = View(timeout=180) 60 | myview.add_item(previousButton) 61 | myview.add_item(nextButton) 62 | 63 | sent_msg = await ctx.send(embed=createHelpEmbed(currentPage), view=myview) 64 | 65 | 66 | # @bot.command(name="help") 67 | # async def Help(ctx): 68 | # embed=Embed(color=0x0080ff, title="Basic Commands") 69 | # embed.add_field(name="dog pic", value="get a cute doggo pic :)", inline=False) 70 | # embed.add_field(name="dog gif", value="get a cute doggo gif :)", inline=False) 71 | # embed.add_field(name="dog play", value="get a cute playing doggo gif :)", inline=False) 72 | # embed.add_field(name="dog sleep", value="get a cute sleepy doggo gif :)", inline=False) 73 | # await ctx.send(embed=embed) 74 | 75 | 76 | 77 | 78 | # https://nextcord.readthedocs.io/en/latest/ext/commands/api.html#nextcord.ext.commands.cooldown 79 | @commands.cooldown(1, 2, commands.BucketType.user) 80 | @bot.command(name="hi") 81 | async def SendMessage(ctx): 82 | 83 | async def dropdown_callback(interaction): 84 | for value in dropdown.values: 85 | await ctx.send(random.choice(links[value])) 86 | 87 | option1 = SelectOption(label="chill", value="gif", description="doggo is lonely", emoji="😎") 88 | option2 = SelectOption(label="play", value="play", description="doggo is bored", emoji="🙂") 89 | option3 = SelectOption(label="feed", value="feed", description="doggo is hungry", emoji="😋") 90 | dropdown = Select(placeholder="What would you like to do with doggo?", options=[option1, option2, option3], max_values=3) 91 | dropdown.callback = dropdown_callback 92 | myview = View(timeout=180) 93 | myview.add_item(dropdown) 94 | 95 | await ctx.send('Hello! Are you bored?', view=myview) 96 | 97 | @commands.cooldown(1, 3, commands.BucketType.user) 98 | @bot.command(name="pic") 99 | async def Dog(ctx): 100 | response = requests.get("https://dog.ceo/api/breeds/image/random") 101 | image_link = response.json()["message"] 102 | await ctx.send(image_link) 103 | 104 | @commands.cooldown(1, 3, commands.BucketType.user) 105 | @bot.command(name="gif", aliases=["feed", "play", "sleep"]) 106 | async def Gif(ctx): 107 | await ctx.send(random.choice(links[ctx.invoked_with])) 108 | 109 | 110 | async def schedule_daily_message(h, m, s, msg, channelid): 111 | while True: 112 | now = datetime.datetime.now() 113 | # then = now+datetime.timedelta(days=1) 114 | then = now.replace(hour=h, minute=m, second=s) 115 | if then < now: 116 | then += datetime.timedelta(days=1) 117 | wait_time = (then-now).total_seconds() 118 | await asyncio.sleep(wait_time) 119 | 120 | channel = bot.get_channel(channelid) 121 | 122 | await channel.send(msg) 123 | await channel.send(random.choice(links["play"])) 124 | await asyncio.sleep(1) 125 | 126 | # dog daily "good morning" 8 30 127 | 128 | @commands.cooldown(1, 20, commands.BucketType.user) 129 | @bot.command(name="daily") 130 | async def daily(ctx, mystr:str, hour:int, minute:int, second:int): 131 | print(mystr, hour, minute, second) 132 | 133 | if not (0 < hour < 24 and 0 <= minute <= 60 and 0 <= second < 60): 134 | raise commands.BadArgument() 135 | 136 | time = datetime.time(hour, minute, second) 137 | timestr = time.strftime("%I:%M:%S %p") 138 | await ctx.send(f"A daily message will be sent at {timestr} everyday in this channel.\nDaily message:\"{mystr}\"\nConfirm by simply saying: `yes`") 139 | 140 | @daily.error 141 | async def daily_error(ctx, error): 142 | if isinstance(error, commands.BadArgument): 143 | await ctx.send("""Incorrect format. Use the command this way: `dog daily "message" hour minute second`. 144 | For example: `dog daily "good morning" 22 30 0` for a message to be sent at 10:30 everyday""") 145 | 146 | # dog speak hello world!! 147 | 148 | # @bot.command(name='hi') 149 | # async def hi(ctx, *args): 150 | 151 | # hi = Button(style=ButtonStyle.primary, label="hi") 152 | # bye = Button(style=ButtonStyle.danger, label="bye") 153 | # sub = Button(style=ButtonStyle.primary, label="sub!!", url="https://www.youtube.com/channel/UCqRLiT8Kv5RVmoNtnshKZwA?sub_confirmation=1") 154 | 155 | 156 | # async def hi_callback(interaction): 157 | # await interaction.response.send_message("Hello!!") 158 | # async def bye_callback(interaction): 159 | # await interaction.response.send_message("Bye :(") 160 | 161 | # hi.callback = hi_callback 162 | # bye.callback = bye_callback 163 | 164 | # myview = View(timeout=180) 165 | # for interaction in [sub, hi, bye]: 166 | # myview.add_item(interaction) 167 | 168 | # await ctx.send(f"hi {ctx.message.author.mention}", view=myview) 169 | 170 | 171 | @bot.command(name='support') 172 | async def support(ctx, *args): 173 | hi = Button(label="click me", style=ButtonStyle.blurple) 174 | 175 | async def hi_callback(interaction): 176 | await interaction.response.send_message("Hello!!") 177 | 178 | hi.callback = hi_callback 179 | 180 | myview = View(timeout=180) 181 | myview.add_item(hi) 182 | 183 | await ctx.send(f"hi {ctx.message.author.mention}", view=myview) 184 | 185 | # @commands.cooldown(1, 5, commands.BucketType.user) 186 | # @bot.command(name='speak') 187 | @bot.slash_command(guild_ids=[910701806231904297]) 188 | async def speak(interaction: Interaction, msg:str, fontSize: int = SlashOption( 189 | name="picker", 190 | choices={"30pt": 30, "50pt": 50, "70pt": 70}, 191 | )): 192 | # msg = " ".join(args) 193 | 194 | font = ImageFont.truetype("PatrickHand-Regular.ttf", fontSize) 195 | img = Image.open("dog.jpg") 196 | cx, cy = (350, 230) 197 | 198 | lines = textwrap.wrap(msg, width=20) 199 | print(lines) 200 | w, h = font.getsize(msg) 201 | y_offset = (len(lines)*h)/2 202 | y_text = cy-(h/2) - y_offset 203 | 204 | for line in lines: 205 | draw = ImageDraw.Draw(img) 206 | w, h = font.getsize(line) 207 | draw.text((cx-(w/2), y_text), line, (0, 0, 0), font=font) 208 | img.save("dog-edited.jpg") 209 | y_text += h 210 | 211 | with open("dog-edited.jpg", "rb") as f: 212 | img = File(f) 213 | # await ctx.channel.send(file=img) 214 | # ephermal to hide msg 215 | await interaction.response.send_message(file=img, ephemeral=True) 216 | 217 | @bot.event 218 | async def on_command_error(ctx, error): 219 | if isinstance(error, commands.CommandOnCooldown): 220 | em = Embed(title=f"Slow it down bro!",description=f"Try again in {error.retry_after:.2f}s.", color=Color.red()) 221 | await ctx.send(embed=em) 222 | else: 223 | print(error) 224 | 225 | @bot.event 226 | async def on_ready(): 227 | print(f"Loggined in as: {bot.user.name}") 228 | # await schedule_daily_message() 229 | 230 | if __name__ == '__main__': 231 | bot.run("PASTE YOUR TOKEN HERE") -------------------------------------------------------------------------------- /part12.py: -------------------------------------------------------------------------------- 1 | from distutils.log import debug 2 | from matplotlib import image 3 | from matplotlib.pyplot import text 4 | from nextcord.ext import commands 5 | from pathvalidate import validate_symbol 6 | import requests, json, random, datetime, asyncio 7 | from PIL import Image, ImageFont, ImageDraw 8 | import textwrap 9 | from nextcord import File, ButtonStyle, Embed, Color, SelectOption, Intents, Interaction, SlashOption, Member 10 | from nextcord.ui import Button, View, Select 11 | 12 | # pip install nextcord --upgrade 13 | # reinvite bot with bot AND application.commands perm 14 | # https://docs.nextcord.dev/en/stable/interactions.html 15 | 16 | links = json.load(open("gifs.json")) 17 | helpGuide = json.load(open("help.json")) 18 | 19 | intents = Intents.default() 20 | intents.message_content = True 21 | intents.members = True 22 | bot = commands.Bot(command_prefix="dog ", intents=intents) 23 | bot.remove_command("help") 24 | 25 | # create help embed using page number and helpGuide 26 | def createHelpEmbed(pageNum=0, inline=False): 27 | pageNum = (pageNum) % len(list(helpGuide)) 28 | pageTitle = list(helpGuide)[pageNum] 29 | embed=Embed(color=0x0080ff, title=pageTitle) 30 | for key, val in helpGuide[pageTitle].items(): 31 | embed.add_field(name=bot.command_prefix+key, value=val, inline=inline) 32 | embed.set_footer(text=f"Page {pageNum+1} of {len(list(helpGuide))}") 33 | return embed 34 | 35 | @bot.command(name="profile") 36 | async def Profile(ctx, user: Member=None): 37 | if user == None: 38 | user = ctx.message.author 39 | inline = True 40 | embed=Embed(title=user.name+"#"+user.discriminator, color=0x0080ff) 41 | userData = { 42 | "Mention" : user.mention, 43 | "Nick" : user.nick, 44 | "Created at" : user.created_at.strftime("%b %d, %Y, %T"), 45 | "Joined at" : user.joined_at.strftime("%b %d, %Y, %T"), 46 | "Server" : user.guild, 47 | "Top role" : user.top_role 48 | } 49 | for [fieldName, fieldVal] in userData.items(): 50 | embed.add_field(name=fieldName+":", value=fieldVal, inline=inline) 51 | embed.set_footer(text=f"id: {user.id}") 52 | 53 | embed.set_thumbnail(user.display_avatar) 54 | await ctx.send(embed=embed) 55 | 56 | # for server 57 | # descriptionIn embeds.0.thumbnail.url: Scheme "none" is not supported. Scheme must be one of ('http', 'https'). 58 | # member count 59 | # online count 60 | # icon 61 | # owner name 62 | # created at 63 | 64 | @bot.command(name="server", pass_context=True) 65 | async def Server(ctx): 66 | guild = ctx.message.author.guild 67 | inline = True 68 | embed=Embed(title=guild.name, color=0x0080ff) 69 | userData = { 70 | "Owner" : guild.owner.mention, 71 | "Channels" : len(guild.channels), 72 | "Members" : guild.member_count, 73 | "Created at" : guild.created_at.strftime("%b %d, %Y, %T"), 74 | "Description" : guild.description, 75 | # "Active" : guild.presence_count, 76 | } 77 | for [fieldName, fieldVal] in userData.items(): 78 | embed.add_field(name=fieldName+":", value=fieldVal, inline=inline) 79 | embed.set_footer(text=f"id: {guild.id}") 80 | 81 | embed.set_thumbnail(guild.icon) 82 | await ctx.send(embed=embed) 83 | 84 | @bot.command(name="help") 85 | async def Help(ctx): 86 | currentPage = 0 87 | 88 | # functionality for buttons 89 | 90 | async def next_callback(interaction): 91 | nonlocal currentPage, sent_msg 92 | currentPage += 1 93 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 94 | 95 | async def previous_callback(interaction): 96 | nonlocal currentPage, sent_msg 97 | currentPage -= 1 98 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 99 | 100 | 101 | 102 | # add buttons to embed 103 | 104 | previousButton = Button(label="<", style=ButtonStyle.blurple) 105 | nextButton = Button(label=">", style=ButtonStyle.blurple) 106 | previousButton.callback = previous_callback 107 | nextButton.callback = next_callback 108 | 109 | myview = View(timeout=180) 110 | myview.add_item(previousButton) 111 | myview.add_item(nextButton) 112 | 113 | sent_msg = await ctx.send(embed=createHelpEmbed(currentPage), view=myview) 114 | 115 | 116 | # @bot.command(name="help") 117 | # async def Help(ctx): 118 | # embed=Embed(color=0x0080ff, title="Basic Commands") 119 | # embed.add_field(name="dog pic", value="get a cute doggo pic :)", inline=False) 120 | # embed.add_field(name="dog gif", value="get a cute doggo gif :)", inline=False) 121 | # embed.add_field(name="dog play", value="get a cute playing doggo gif :)", inline=False) 122 | # embed.add_field(name="dog sleep", value="get a cute sleepy doggo gif :)", inline=False) 123 | # await ctx.send(embed=embed) 124 | 125 | 126 | 127 | # https://nextcord.readthedocs.io/en/latest/ext/commands/api.html#nextcord.ext.commands.cooldown 128 | @commands.cooldown(1, 2, commands.BucketType.user) 129 | @bot.command(name="hi") 130 | async def SendMessage(ctx): 131 | 132 | async def dropdown_callback(interaction): 133 | for value in dropdown.values: 134 | await ctx.send(random.choice(links[value])) 135 | 136 | option1 = SelectOption(label="chill", value="gif", description="doggo is lonely", emoji="😎") 137 | option2 = SelectOption(label="play", value="play", description="doggo is bored", emoji="🙂") 138 | option3 = SelectOption(label="feed", value="feed", description="doggo is hungry", emoji="😋") 139 | dropdown = Select(placeholder="What would you like to do with doggo?", options=[option1, option2, option3], max_values=3) 140 | dropdown.callback = dropdown_callback 141 | myview = View(timeout=180) 142 | myview.add_item(dropdown) 143 | 144 | await ctx.send('Hello! Are you bored?', view=myview) 145 | 146 | @commands.cooldown(1, 3, commands.BucketType.user) 147 | @bot.command(name="pic") 148 | async def Dog(ctx): 149 | response = requests.get("https://dog.ceo/api/breeds/image/random") 150 | image_link = response.json()["message"] 151 | await ctx.send(image_link) 152 | 153 | @commands.cooldown(1, 3, commands.BucketType.user) 154 | @bot.command(name="gif", aliases=["feed", "play", "sleep"]) 155 | async def Gif(ctx): 156 | await ctx.send(random.choice(links[ctx.invoked_with])) 157 | 158 | 159 | async def schedule_daily_message(h, m, s, msg, channelid): 160 | while True: 161 | now = datetime.datetime.now() 162 | # then = now+datetime.timedelta(days=1) 163 | then = now.replace(hour=h, minute=m, second=s) 164 | if then < now: 165 | then += datetime.timedelta(days=1) 166 | wait_time = (then-now).total_seconds() 167 | await asyncio.sleep(wait_time) 168 | 169 | channel = bot.get_channel(channelid) 170 | 171 | await channel.send(msg) 172 | await channel.send(random.choice(links["play"])) 173 | await asyncio.sleep(1) 174 | 175 | # dog daily "good morning" 8 30 176 | 177 | @commands.cooldown(1, 20, commands.BucketType.user) 178 | @bot.command(name="daily") 179 | async def daily(ctx, mystr:str, hour:int, minute:int, second:int): 180 | print(mystr, hour, minute, second) 181 | 182 | if not (0 < hour < 24 and 0 <= minute <= 60 and 0 <= second < 60): 183 | raise commands.BadArgument() 184 | 185 | time = datetime.time(hour, minute, second) 186 | timestr = time.strftime("%I:%M:%S %p") 187 | await ctx.send(f"A daily message will be sent at {timestr} everyday in this channel.\nDaily message:\"{mystr}\"\nConfirm by simply saying: `yes`") 188 | 189 | @daily.error 190 | async def daily_error(ctx, error): 191 | if isinstance(error, commands.BadArgument): 192 | await ctx.send("""Incorrect format. Use the command this way: `dog daily "message" hour minute second`. 193 | For example: `dog daily "good morning" 22 30 0` for a message to be sent at 10:30 everyday""") 194 | 195 | # dog speak hello world!! 196 | 197 | # @bot.command(name='hi') 198 | # async def hi(ctx, *args): 199 | 200 | # hi = Button(style=ButtonStyle.primary, label="hi") 201 | # bye = Button(style=ButtonStyle.danger, label="bye") 202 | # sub = Button(style=ButtonStyle.primary, label="sub!!", url="https://www.youtube.com/channel/UCqRLiT8Kv5RVmoNtnshKZwA?sub_confirmation=1") 203 | 204 | 205 | # async def hi_callback(interaction): 206 | # await interaction.response.send_message("Hello!!") 207 | # async def bye_callback(interaction): 208 | # await interaction.response.send_message("Bye :(") 209 | 210 | # hi.callback = hi_callback 211 | # bye.callback = bye_callback 212 | 213 | # myview = View(timeout=180) 214 | # for interaction in [sub, hi, bye]: 215 | # myview.add_item(interaction) 216 | 217 | # await ctx.send(f"hi {ctx.message.author.mention}", view=myview) 218 | 219 | 220 | @bot.command(name='support') 221 | async def support(ctx, *args): 222 | hi = Button(label="click me", style=ButtonStyle.blurple) 223 | 224 | async def hi_callback(interaction): 225 | await interaction.response.send_message("Hello!!") 226 | 227 | hi.callback = hi_callback 228 | 229 | myview = View(timeout=180) 230 | myview.add_item(hi) 231 | 232 | await ctx.send(f"hi {ctx.message.author.mention}", view=myview) 233 | 234 | # @commands.cooldown(1, 5, commands.BucketType.user) 235 | # @bot.command(name='speak') 236 | @bot.slash_command(guild_ids=[910701806231904297]) 237 | async def speak(interaction: Interaction, msg:str, fontSize: int = SlashOption( 238 | name="picker", 239 | choices={"30pt": 30, "50pt": 50, "70pt": 70}, 240 | )): 241 | # msg = " ".join(args) 242 | 243 | font = ImageFont.truetype("PatrickHand-Regular.ttf", fontSize) 244 | img = Image.open("dog.jpg") 245 | cx, cy = (350, 230) 246 | 247 | lines = textwrap.wrap(msg, width=20) 248 | print(lines) 249 | w, h = font.getsize(msg) 250 | y_offset = (len(lines)*h)/2 251 | y_text = cy-(h/2) - y_offset 252 | 253 | for line in lines: 254 | draw = ImageDraw.Draw(img) 255 | w, h = font.getsize(line) 256 | draw.text((cx-(w/2), y_text), line, (0, 0, 0), font=font) 257 | img.save("dog-edited.jpg") 258 | y_text += h 259 | 260 | with open("dog-edited.jpg", "rb") as f: 261 | img = File(f) 262 | # await ctx.channel.send(file=img) 263 | # ephermal to hide msg 264 | await interaction.response.send_message(file=img, ephemeral=True) 265 | 266 | @bot.event 267 | async def on_command_error(ctx, error): 268 | if isinstance(error, commands.CommandOnCooldown): 269 | em = Embed(title=f"Slow it down bro!",description=f"Try again in {error.retry_after:.2f}s.", color=Color.red()) 270 | await ctx.send(embed=em) 271 | else: 272 | print(error) 273 | 274 | @bot.event 275 | async def on_ready(): 276 | print(f"Loggined in as: {bot.user.name}") 277 | # await schedule_daily_message() 278 | 279 | if __name__ == '__main__': 280 | bot.run("PASTE YOUR TOKEN HERE") -------------------------------------------------------------------------------- /part13.py: -------------------------------------------------------------------------------- 1 | from distutils.log import debug 2 | from matplotlib import image 3 | from matplotlib.pyplot import text 4 | from nextcord.ext import commands 5 | from pathvalidate import validate_symbol 6 | import requests 7 | import json 8 | import random 9 | import datetime 10 | import asyncio 11 | from PIL import Image, ImageFont, ImageDraw 12 | import textwrap 13 | from nextcord import File, ButtonStyle, Embed, Color, SelectOption, Intents, Interaction, SlashOption, Member 14 | from nextcord.ui import Button, View, Select 15 | import nextcord 16 | from gtts import gTTS 17 | import pyttsx3 18 | 19 | # engine = pyttsx3.init('sapi5') 20 | # voices = engine.getProperty('voices') 21 | # engine.setProperty('voice', voices[1].id) 22 | # engine.setProperty('rate', 130) 23 | 24 | 25 | # pip install nextcord --upgrade 26 | # reinvite bot with bot AND application.commands perm 27 | # https://docs.nextcord.dev/en/stable/interactions.html 28 | 29 | links = json.load(open("gifs.json")) 30 | helpGuide = json.load(open("help.json")) 31 | 32 | intents = Intents.default() 33 | intents.message_content = True 34 | intents.members = True 35 | bot = commands.Bot(command_prefix="dog ", intents=intents) 36 | bot.remove_command("help") 37 | 38 | # create help embed using page number and helpGuide 39 | 40 | 41 | def createHelpEmbed(pageNum=0, inline=False): 42 | pageNum = (pageNum) % len(list(helpGuide)) 43 | pageTitle = list(helpGuide)[pageNum] 44 | embed = Embed(color=0x0080ff, title=pageTitle) 45 | for key, val in helpGuide[pageTitle].items(): 46 | embed.add_field(name=bot.command_prefix+key, value=val, inline=inline) 47 | embed.set_footer(text=f"Page {pageNum+1} of {len(list(helpGuide))}") 48 | return embed 49 | 50 | 51 | @bot.command(name="profile") 52 | async def Profile(ctx, user: Member = None): 53 | if user == None: 54 | user = ctx.message.author 55 | inline = True 56 | embed = Embed(title=user.name+"#"+user.discriminator, color=0x0080ff) 57 | userData = { 58 | "Mention": user.mention, 59 | "Nick": user.nick, 60 | "Created at": user.created_at.strftime("%b %d, %Y, %T"), 61 | "Joined at": user.joined_at.strftime("%b %d, %Y, %T"), 62 | "Server": user.guild, 63 | "Top role": user.top_role 64 | } 65 | for [fieldName, fieldVal] in userData.items(): 66 | embed.add_field(name=fieldName+":", value=fieldVal, inline=inline) 67 | embed.set_footer(text=f"id: {user.id}") 68 | 69 | embed.set_thumbnail(user.display_avatar) 70 | await ctx.send(embed=embed) 71 | 72 | # for server 73 | # descriptionIn embeds.0.thumbnail.url: Scheme "none" is not supported. Scheme must be one of ('http', 'https'). 74 | # member count 75 | # online count 76 | # icon 77 | # owner name 78 | # created at 79 | 80 | 81 | @bot.command(name="server", pass_context=True) 82 | async def Server(ctx): 83 | guild = ctx.message.author.guild 84 | inline = True 85 | embed = Embed(title=guild.name, color=0x0080ff) 86 | userData = { 87 | "Owner": guild.owner.mention, 88 | "Channels": len(guild.channels), 89 | "Members": guild.member_count, 90 | "Created at": guild.created_at.strftime("%b %d, %Y, %T"), 91 | "Description": guild.description, 92 | # "Active" : guild.presence_count, 93 | } 94 | for [fieldName, fieldVal] in userData.items(): 95 | embed.add_field(name=fieldName+":", value=fieldVal, inline=inline) 96 | embed.set_footer(text=f"id: {guild.id}") 97 | 98 | embed.set_thumbnail(guild.icon) 99 | await ctx.send(embed=embed) 100 | 101 | 102 | @bot.command(name="help") 103 | async def Help(ctx): 104 | currentPage = 0 105 | 106 | # functionality for buttons 107 | 108 | async def next_callback(interaction): 109 | nonlocal currentPage, sent_msg 110 | currentPage += 1 111 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 112 | 113 | async def previous_callback(interaction): 114 | nonlocal currentPage, sent_msg 115 | currentPage -= 1 116 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 117 | 118 | # add buttons to embed 119 | 120 | previousButton = Button(label="<", style=ButtonStyle.blurple) 121 | nextButton = Button(label=">", style=ButtonStyle.blurple) 122 | previousButton.callback = previous_callback 123 | nextButton.callback = next_callback 124 | 125 | myview = View(timeout=180) 126 | myview.add_item(previousButton) 127 | myview.add_item(nextButton) 128 | 129 | sent_msg = await ctx.send(embed=createHelpEmbed(currentPage), view=myview) 130 | 131 | 132 | # @bot.command(name="help") 133 | # async def Help(ctx): 134 | # embed=Embed(color=0x0080ff, title="Basic Commands") 135 | # embed.add_field(name="dog pic", value="get a cute doggo pic :)", inline=False) 136 | # embed.add_field(name="dog gif", value="get a cute doggo gif :)", inline=False) 137 | # embed.add_field(name="dog play", value="get a cute playing doggo gif :)", inline=False) 138 | # embed.add_field(name="dog sleep", value="get a cute sleepy doggo gif :)", inline=False) 139 | # await ctx.send(embed=embed) 140 | 141 | 142 | # https://nextcord.readthedocs.io/en/latest/ext/commands/api.html#nextcord.ext.commands.cooldown 143 | @commands.cooldown(1, 2, commands.BucketType.user) 144 | @bot.command(name="hi") 145 | async def SendMessage(ctx): 146 | 147 | async def dropdown_callback(interaction): 148 | for value in dropdown.values: 149 | await ctx.send(random.choice(links[value])) 150 | 151 | option1 = SelectOption(label="chill", value="gif", 152 | description="doggo is lonely", emoji="😎") 153 | option2 = SelectOption(label="play", value="play", 154 | description="doggo is bored", emoji="🙂") 155 | option3 = SelectOption(label="feed", value="feed", 156 | description="doggo is hungry", emoji="😋") 157 | dropdown = Select(placeholder="What would you like to do with doggo?", options=[ 158 | option1, option2, option3], max_values=3) 159 | dropdown.callback = dropdown_callback 160 | myview = View(timeout=180) 161 | myview.add_item(dropdown) 162 | 163 | await ctx.send('Hello! Are you bored?', view=myview) 164 | 165 | 166 | @commands.cooldown(1, 3, commands.BucketType.user) 167 | @bot.command(name="pic") 168 | async def Dog(ctx): 169 | response = requests.get("https://dog.ceo/api/breeds/image/random") 170 | image_link = response.json()["message"] 171 | await ctx.send(image_link) 172 | 173 | 174 | @commands.cooldown(1, 3, commands.BucketType.user) 175 | @bot.command(name="gif", aliases=["feed", "play", "sleep"]) 176 | async def Gif(ctx): 177 | await ctx.send(random.choice(links[ctx.invoked_with])) 178 | 179 | 180 | async def schedule_daily_message(h, m, s, msg, channelid): 181 | while True: 182 | now = datetime.datetime.now() 183 | # then = now+datetime.timedelta(days=1) 184 | then = now.replace(hour=h, minute=m, second=s) 185 | if then < now: 186 | then += datetime.timedelta(days=1) 187 | wait_time = (then-now).total_seconds() 188 | await asyncio.sleep(wait_time) 189 | 190 | channel = bot.get_channel(channelid) 191 | 192 | await channel.send(msg) 193 | await channel.send(random.choice(links["play"])) 194 | await asyncio.sleep(1) 195 | 196 | # dog daily "good morning" 8 30 197 | 198 | 199 | @commands.cooldown(1, 20, commands.BucketType.user) 200 | @bot.command(name="daily") 201 | async def daily(ctx, mystr: str, hour: int, minute: int, second: int): 202 | print(mystr, hour, minute, second) 203 | 204 | if not (0 < hour < 24 and 0 <= minute <= 60 and 0 <= second < 60): 205 | raise commands.BadArgument() 206 | 207 | time = datetime.time(hour, minute, second) 208 | timestr = time.strftime("%I:%M:%S %p") 209 | await ctx.send(f"A daily message will be sent at {timestr} everyday in this channel.\nDaily message:\"{mystr}\"\nConfirm by simply saying: `yes`") 210 | 211 | 212 | @daily.error 213 | async def daily_error(ctx, error): 214 | if isinstance(error, commands.BadArgument): 215 | await ctx.send("""Incorrect format. Use the command this way: `dog daily "message" hour minute second`. 216 | For example: `dog daily "good morning" 22 30 0` for a message to be sent at 10:30 everyday""") 217 | 218 | # dog speak hello world!! 219 | 220 | # @bot.command(name='hi') 221 | # async def hi(ctx, *args): 222 | 223 | # hi = Button(style=ButtonStyle.primary, label="hi") 224 | # bye = Button(style=ButtonStyle.danger, label="bye") 225 | # sub = Button(style=ButtonStyle.primary, label="sub!!", url="https://www.youtube.com/channel/UCqRLiT8Kv5RVmoNtnshKZwA?sub_confirmation=1") 226 | 227 | 228 | # async def hi_callback(interaction): 229 | # await interaction.response.send_message("Hello!!") 230 | # async def bye_callback(interaction): 231 | # await interaction.response.send_message("Bye :(") 232 | 233 | # hi.callback = hi_callback 234 | # bye.callback = bye_callback 235 | 236 | # myview = View(timeout=180) 237 | # for interaction in [sub, hi, bye]: 238 | # myview.add_item(interaction) 239 | 240 | # await ctx.send(f"hi {ctx.message.author.mention}", view=myview) 241 | 242 | 243 | @bot.command(name='support') 244 | async def support(ctx, *args): 245 | hi = Button(label="click me", style=ButtonStyle.blurple) 246 | 247 | async def hi_callback(interaction): 248 | await interaction.response.send_message("Hello!!") 249 | 250 | hi.callback = hi_callback 251 | 252 | myview = View(timeout=180) 253 | myview.add_item(hi) 254 | 255 | await ctx.send(f"hi {ctx.message.author.mention}", view=myview) 256 | 257 | 258 | 259 | # @bot.slash_command(guild_ids=[910701806231904297]) 260 | # async def speak(interaction: Interaction, msg: str, fontSize: int = SlashOption( 261 | # name="picker", 262 | # choices={"30pt": 30, "50pt": 50, "70pt": 70}, 263 | # )): 264 | @commands.cooldown(1, 5, commands.BucketType.user) 265 | @bot.command(name='speak') 266 | async def speak(ctx, *args): 267 | msg = " ".join(args) 268 | 269 | font = ImageFont.truetype("PatrickHand-Regular.ttf", 50) 270 | img = Image.open("dog.jpg") 271 | cx, cy = (350, 230) 272 | 273 | lines = textwrap.wrap(msg, width=20) 274 | print(lines) 275 | w, h = font.getsize(msg) 276 | y_offset = (len(lines)*h)/2 277 | y_text = cy-(h/2) - y_offset 278 | 279 | for line in lines: 280 | draw = ImageDraw.Draw(img) 281 | w, h = font.getsize(line) 282 | draw.text((cx-(w/2), y_text), line, (0, 0, 0), font=font) 283 | img.save("dog-edited.jpg") 284 | y_text += h 285 | 286 | with open("dog-edited.jpg", "rb") as f: 287 | img = File(f) 288 | await ctx.channel.send(file=img) 289 | # ephermal to hide msg 290 | # await interaction.response.send_message(file=img, ephemeral=True) 291 | 292 | 293 | @bot.event 294 | async def on_command_error(ctx, error): 295 | if isinstance(error, commands.CommandOnCooldown): 296 | em = Embed(title=f"Slow it down bro!", 297 | description=f"Try again in {error.retry_after:.2f}s.", color=Color.red()) 298 | await ctx.send(embed=em) 299 | else: 300 | print(error) 301 | 302 | @bot.command(name='leave') 303 | async def leave(ctx): 304 | await ctx.voice_client.disconnect() 305 | await ctx.send("👋") 306 | 307 | @bot.command(name='stop') 308 | async def leave(ctx): 309 | user = ctx.message.author 310 | if user.voice != None: 311 | try: 312 | vc = ctx.voice_client 313 | except: 314 | await ctx.send("there is nothing to stop") 315 | if vc != None and vc.is_playing(): 316 | vc.stop() 317 | await ctx.send("stopped") 318 | else: 319 | await ctx.send("there is nothing to stop") 320 | 321 | @bot.command(name='join') 322 | async def stop(ctx): 323 | user = ctx.message.author 324 | if user.voice != None: 325 | try: 326 | await user.voice.channel.connect() 327 | except: 328 | await ctx.send("I'm already in the vc!") 329 | else: 330 | await ctx.send('You need to be in a vc to run this command!') 331 | 332 | @bot.command(name='bark') 333 | async def bark(ctx): 334 | user = ctx.message.author 335 | if user.voice != None: 336 | try: 337 | vc = await user.voice.channel.connect() 338 | except: 339 | vc = ctx.voice_client 340 | if vc.is_playing(): 341 | vc.stop() 342 | source = await nextcord.FFmpegOpusAudio.from_probe("dog-bark.mp3", method='fallback') 343 | vc.play(source) 344 | else: 345 | await ctx.send('You need to be in a vc to run this command!') 346 | 347 | 348 | @bot.command(name='tts') 349 | async def tts(ctx, *args): 350 | text = " ".join(args) 351 | user = ctx.message.author 352 | if user.voice != None: 353 | try: 354 | vc = await user.voice.channel.connect() 355 | except: 356 | vc = ctx.voice_client 357 | if vc.is_playing(): 358 | vc.stop() 359 | 360 | myobj = gTTS(text=text, lang="en", slow=False) 361 | myobj.save("tts-audio.mp3") 362 | 363 | source = await nextcord.FFmpegOpusAudio.from_probe("tts-audio.mp3", method='fallback') 364 | vc.play(source) 365 | else: 366 | await ctx.send('You need to be in a vc to run this command!') 367 | 368 | @bot.event 369 | async def on_ready(): 370 | print(f"Loggined in as: {bot.user.name}") 371 | 372 | if __name__ == '__main__': 373 | bot.run("PASTE YOUR TOKEN HERE") 374 | -------------------------------------------------------------------------------- /part14.py: -------------------------------------------------------------------------------- 1 | from distutils.log import debug, error 2 | from matplotlib import image 3 | from matplotlib.pyplot import text 4 | from nextcord.ext import commands 5 | from pathvalidate import validate_symbol 6 | import requests 7 | import json 8 | import random 9 | import datetime 10 | import asyncio 11 | from PIL import Image, ImageFont, ImageDraw 12 | import textwrap 13 | from nextcord import File, ButtonStyle, Embed, Color, SelectOption, Intents, Interaction, SlashOption, Member 14 | from nextcord.ui import Button, View, Select 15 | import nextcord 16 | from gtts import gTTS 17 | import pyttsx3 18 | 19 | # engine = pyttsx3.init('sapi5') 20 | # voices = engine.getProperty('voices') 21 | # engine.setProperty('voice', voices[1].id) 22 | # engine.setProperty('rate', 130) 23 | 24 | 25 | # pip install nextcord --upgrade 26 | # reinvite bot with bot AND application.commands perm 27 | # https://docs.nextcord.dev/en/stable/interactions.html 28 | 29 | links = json.load(open("gifs.json")) 30 | helpGuide = json.load(open("help.json")) 31 | 32 | intents = Intents.default() 33 | intents.message_content = True 34 | intents.members = True 35 | bot = commands.Bot(command_prefix="dog ", intents=intents) 36 | bot.remove_command("help") 37 | 38 | # create help embed using page number and helpGuide 39 | 40 | 41 | def createHelpEmbed(pageNum=0, inline=False): 42 | pageNum = (pageNum) % len(list(helpGuide)) 43 | pageTitle = list(helpGuide)[pageNum] 44 | embed = Embed(color=0x0080ff, title=pageTitle) 45 | for key, val in helpGuide[pageTitle].items(): 46 | embed.add_field(name=bot.command_prefix+key, value=val, inline=inline) 47 | embed.set_footer(text=f"Page {pageNum+1} of {len(list(helpGuide))}") 48 | return embed 49 | 50 | 51 | @bot.event 52 | async def on_command_error(ctx, error): 53 | if isinstance(error, commands.CommandOnCooldown): 54 | em = Embed(title=f"Slow it down bro!", 55 | description=f"Try again in {error.retry_after:.2f}s.", color=Color.red()) 56 | await ctx.send(embed=em) 57 | elif isinstance(error, commands.MissingPermissions): 58 | await ctx.send("You don't have the permissions to do that!") 59 | elif isinstance(error, commands.MemberNotFound): 60 | await ctx.send("Member not found.") 61 | else: 62 | print(type(error)) 63 | print(error) 64 | 65 | @bot.command(name="ban") 66 | @commands.has_permissions(ban_members=True) 67 | async def Ban(ctx, user: Member, reason=None, delete_message_days=1): 68 | await ctx.message.author.guild.ban(user, reason=reason, delete_message_days=delete_message_days) 69 | embed = Embed(title="successfully banned user", color=nextcord.Color.red()) 70 | embedData = { 71 | "Member": user.mention, 72 | "Reason for ban": reason, 73 | "Days of messages deleted" : delete_message_days 74 | } 75 | for [fieldName, fieldVal] in embedData.items(): 76 | embed.add_field(name=fieldName+":", value=fieldVal, inline=False) 77 | await ctx.send(embed=embed) 78 | 79 | 80 | @bot.command(name="unban") 81 | @commands.has_permissions(ban_members=True) 82 | async def Unban(ctx, userId: int, reason=None): 83 | user = await bot.fetch_user(userId) 84 | await ctx.message.author.guild.unban(user, reason=reason) 85 | embed = Embed(title="successfully unbanned user", color=nextcord.Color.green()) 86 | embedData = { 87 | "Member": user.mention, 88 | "Reason for unban": reason, 89 | } 90 | for [fieldName, fieldVal] in embedData.items(): 91 | embed.add_field(name=fieldName+":", value=fieldVal, inline=False) 92 | await ctx.send(embed=embed) 93 | 94 | @bot.command(name="kick") 95 | @commands.has_permissions(ban_members=True) 96 | async def Kick(ctx, user: Member, reason=None): 97 | await ctx.message.author.guild.kick(user, reason=reason) 98 | embed = Embed(title="successfully kicked user", color=nextcord.Color.red()) 99 | embedData = { 100 | "Member": user.mention, 101 | "Reason for ban": reason, 102 | } 103 | for [fieldName, fieldVal] in embedData.items(): 104 | embed.add_field(name=fieldName+":", value=fieldVal, inline=False) 105 | await ctx.send(embed=embed) 106 | 107 | 108 | @bot.command(name="profile") 109 | async def Profile(ctx, user: Member = None): 110 | if user == None: 111 | user = ctx.message.author 112 | inline = True 113 | embed = Embed(title=user.name+"#"+user.discriminator, color=0x0080ff) 114 | userData = { 115 | "Mention": user.mention, 116 | "Nick": user.nick, 117 | "Created at": user.created_at.strftime("%b %d, %Y, %T"), 118 | "Joined at": user.joined_at.strftime("%b %d, %Y, %T"), 119 | "Server": user.guild, 120 | "Top role": user.top_role 121 | } 122 | for [fieldName, fieldVal] in userData.items(): 123 | embed.add_field(name=fieldName+":", value=fieldVal, inline=inline) 124 | embed.set_footer(text=f"id: {user.id}") 125 | 126 | embed.set_thumbnail(user.display_avatar) 127 | await ctx.send(embed=embed) 128 | 129 | # for server 130 | # descriptionIn embeds.0.thumbnail.url: Scheme "none" is not supported. Scheme must be one of ('http', 'https'). 131 | # member count 132 | # online count 133 | # icon 134 | # owner name 135 | # created at 136 | 137 | 138 | @bot.command(name="server", pass_context=True) 139 | async def Server(ctx): 140 | guild = ctx.message.author.guild 141 | inline = True 142 | embed = Embed(title=guild.name, color=0x0080ff) 143 | userData = { 144 | "Owner": guild.owner.mention, 145 | "Channels": len(guild.channels), 146 | "Members": guild.member_count, 147 | "Created at": guild.created_at.strftime("%b %d, %Y, %T"), 148 | "Description": guild.description, 149 | # "Active" : guild.presence_count, 150 | } 151 | for [fieldName, fieldVal] in userData.items(): 152 | embed.add_field(name=fieldName+":", value=fieldVal, inline=inline) 153 | embed.set_footer(text=f"id: {guild.id}") 154 | 155 | embed.set_thumbnail(guild.icon) 156 | await ctx.send(embed=embed) 157 | 158 | 159 | @bot.command(name="help") 160 | async def Help(ctx): 161 | currentPage = 0 162 | 163 | # functionality for buttons 164 | 165 | async def next_callback(interaction): 166 | nonlocal currentPage, sent_msg 167 | currentPage += 1 168 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 169 | 170 | async def previous_callback(interaction): 171 | nonlocal currentPage, sent_msg 172 | currentPage -= 1 173 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 174 | 175 | # add buttons to embed 176 | 177 | previousButton = Button(label="<", style=ButtonStyle.blurple) 178 | nextButton = Button(label=">", style=ButtonStyle.blurple) 179 | previousButton.callback = previous_callback 180 | nextButton.callback = next_callback 181 | 182 | myview = View(timeout=180) 183 | myview.add_item(previousButton) 184 | myview.add_item(nextButton) 185 | 186 | sent_msg = await ctx.send(embed=createHelpEmbed(currentPage), view=myview) 187 | 188 | 189 | # @bot.command(name="help") 190 | # async def Help(ctx): 191 | # embed=Embed(color=0x0080ff, title="Basic Commands") 192 | # embed.add_field(name="dog pic", value="get a cute doggo pic :)", inline=False) 193 | # embed.add_field(name="dog gif", value="get a cute doggo gif :)", inline=False) 194 | # embed.add_field(name="dog play", value="get a cute playing doggo gif :)", inline=False) 195 | # embed.add_field(name="dog sleep", value="get a cute sleepy doggo gif :)", inline=False) 196 | # await ctx.send(embed=embed) 197 | 198 | 199 | # https://nextcord.readthedocs.io/en/latest/ext/commands/api.html#nextcord.ext.commands.cooldown 200 | @commands.cooldown(1, 2, commands.BucketType.user) 201 | @bot.command(name="hi") 202 | async def SendMessage(ctx): 203 | 204 | async def dropdown_callback(interaction): 205 | for value in dropdown.values: 206 | await ctx.send(random.choice(links[value])) 207 | 208 | option1 = SelectOption(label="chill", value="gif", 209 | description="doggo is lonely", emoji="😎") 210 | option2 = SelectOption(label="play", value="play", 211 | description="doggo is bored", emoji="🙂") 212 | option3 = SelectOption(label="feed", value="feed", 213 | description="doggo is hungry", emoji="😋") 214 | dropdown = Select(placeholder="What would you like to do with doggo?", options=[ 215 | option1, option2, option3], max_values=3) 216 | dropdown.callback = dropdown_callback 217 | myview = View(timeout=180) 218 | myview.add_item(dropdown) 219 | 220 | await ctx.send('Hello! Are you bored?', view=myview) 221 | 222 | 223 | @commands.cooldown(1, 3, commands.BucketType.user) 224 | @bot.command(name="pic") 225 | async def Dog(ctx): 226 | response = requests.get("https://dog.ceo/api/breeds/image/random") 227 | image_link = response.json()["message"] 228 | await ctx.send(image_link) 229 | 230 | 231 | @commands.cooldown(1, 3, commands.BucketType.user) 232 | @bot.command(name="gif", aliases=["feed", "play", "sleep"]) 233 | async def Gif(ctx): 234 | await ctx.send(random.choice(links[ctx.invoked_with])) 235 | 236 | 237 | async def schedule_daily_message(h, m, s, msg, channelid): 238 | while True: 239 | now = datetime.datetime.now() 240 | # then = now+datetime.timedelta(days=1) 241 | then = now.replace(hour=h, minute=m, second=s) 242 | if then < now: 243 | then += datetime.timedelta(days=1) 244 | wait_time = (then-now).total_seconds() 245 | await asyncio.sleep(wait_time) 246 | 247 | channel = bot.get_channel(channelid) 248 | 249 | await channel.send(msg) 250 | await channel.send(random.choice(links["play"])) 251 | await asyncio.sleep(1) 252 | 253 | # dog daily "good morning" 8 30 254 | 255 | 256 | @commands.cooldown(1, 20, commands.BucketType.user) 257 | @bot.command(name="daily") 258 | async def daily(ctx, mystr: str, hour: int, minute: int, second: int): 259 | print(mystr, hour, minute, second) 260 | 261 | if not (0 < hour < 24 and 0 <= minute <= 60 and 0 <= second < 60): 262 | raise commands.BadArgument() 263 | 264 | time = datetime.time(hour, minute, second) 265 | timestr = time.strftime("%I:%M:%S %p") 266 | await ctx.send(f"A daily message will be sent at {timestr} everyday in this channel.\nDaily message:\"{mystr}\"\nConfirm by simply saying: `yes`") 267 | 268 | 269 | @daily.error 270 | async def daily_error(ctx, error): 271 | if isinstance(error, commands.BadArgument): 272 | await ctx.send("""Incorrect format. Use the command this way: `dog daily "message" hour minute second`. 273 | For example: `dog daily "good morning" 22 30 0` for a message to be sent at 10:30 everyday""") 274 | 275 | # dog speak hello world!! 276 | 277 | # @bot.command(name='hi') 278 | # async def hi(ctx, *args): 279 | 280 | # hi = Button(style=ButtonStyle.primary, label="hi") 281 | # bye = Button(style=ButtonStyle.danger, label="bye") 282 | # sub = Button(style=ButtonStyle.primary, label="sub!!", url="https://www.youtube.com/channel/UCqRLiT8Kv5RVmoNtnshKZwA?sub_confirmation=1") 283 | 284 | 285 | # async def hi_callback(interaction): 286 | # await interaction.response.send_message("Hello!!") 287 | # async def bye_callback(interaction): 288 | # await interaction.response.send_message("Bye :(") 289 | 290 | # hi.callback = hi_callback 291 | # bye.callback = bye_callback 292 | 293 | # myview = View(timeout=180) 294 | # for interaction in [sub, hi, bye]: 295 | # myview.add_item(interaction) 296 | 297 | # await ctx.send(f"hi {ctx.message.author.mention}", view=myview) 298 | 299 | 300 | @bot.command(name='support') 301 | async def support(ctx, *args): 302 | hi = Button(label="click me", style=ButtonStyle.blurple) 303 | 304 | async def hi_callback(interaction): 305 | await interaction.response.send_message("Hello!!") 306 | 307 | hi.callback = hi_callback 308 | 309 | myview = View(timeout=180) 310 | myview.add_item(hi) 311 | 312 | await ctx.send(f"hi {ctx.message.author.mention}", view=myview) 313 | 314 | 315 | 316 | # @bot.slash_command(guild_ids=[910701806231904297]) 317 | # async def speak(interaction: Interaction, msg: str, fontSize: int = SlashOption( 318 | # name="picker", 319 | # choices={"30pt": 30, "50pt": 50, "70pt": 70}, 320 | # )): 321 | @commands.cooldown(1, 5, commands.BucketType.user) 322 | @bot.command(name='speak') 323 | async def speak(ctx, *args): 324 | msg = " ".join(args) 325 | 326 | font = ImageFont.truetype("PatrickHand-Regular.ttf", 50) 327 | img = Image.open("dog.jpg") 328 | cx, cy = (350, 230) 329 | 330 | lines = textwrap.wrap(msg, width=20) 331 | print(lines) 332 | w, h = font.getsize(msg) 333 | y_offset = (len(lines)*h)/2 334 | y_text = cy-(h/2) - y_offset 335 | 336 | for line in lines: 337 | draw = ImageDraw.Draw(img) 338 | w, h = font.getsize(line) 339 | draw.text((cx-(w/2), y_text), line, (0, 0, 0), font=font) 340 | img.save("dog-edited.jpg") 341 | y_text += h 342 | 343 | with open("dog-edited.jpg", "rb") as f: 344 | img = File(f) 345 | await ctx.channel.send(file=img) 346 | # ephermal to hide msg 347 | # await interaction.response.send_message(file=img, ephemeral=True) 348 | 349 | 350 | 351 | @bot.command(name='leave') 352 | async def leave(ctx): 353 | await ctx.voice_client.disconnect() 354 | await ctx.send("👋") 355 | 356 | @bot.command(name='stop') 357 | async def leave(ctx): 358 | user = ctx.message.author 359 | if user.voice != None: 360 | try: 361 | vc = ctx.voice_client 362 | except: 363 | await ctx.send("there is nothing to stop") 364 | if vc != None and vc.is_playing(): 365 | vc.stop() 366 | await ctx.send("stopped") 367 | else: 368 | await ctx.send("there is nothing to stop") 369 | 370 | @bot.command(name='join') 371 | async def stop(ctx): 372 | user = ctx.message.author 373 | if user.voice != None: 374 | try: 375 | await user.voice.channel.connect() 376 | except: 377 | await ctx.send("I'm already in the vc!") 378 | else: 379 | await ctx.send('You need to be in a vc to run this command!') 380 | 381 | @bot.command(name='bark') 382 | async def bark(ctx): 383 | user = ctx.message.author 384 | if user.voice != None: 385 | try: 386 | vc = await user.voice.channel.connect() 387 | except: 388 | vc = ctx.voice_client 389 | if vc.is_playing(): 390 | vc.stop() 391 | source = await nextcord.FFmpegOpusAudio.from_probe("dog-bark.mp3", method='fallback') 392 | vc.play(source) 393 | else: 394 | await ctx.send('You need to be in a vc to run this command!') 395 | 396 | 397 | @bot.command(name='tts') 398 | async def tts(ctx, *args): 399 | text = " ".join(args) 400 | user = ctx.message.author 401 | if user.voice != None: 402 | try: 403 | vc = await user.voice.channel.connect() 404 | except: 405 | vc = ctx.voice_client 406 | if vc.is_playing(): 407 | vc.stop() 408 | 409 | myobj = gTTS(text=text, lang="en", slow=False) 410 | myobj.save("tts-audio.mp3") 411 | 412 | source = await nextcord.FFmpegOpusAudio.from_probe("tts-audio.mp3", method='fallback') 413 | vc.play(source) 414 | else: 415 | await ctx.send('You need to be in a vc to run this command!') 416 | 417 | @bot.event 418 | async def on_ready(): 419 | print(f"Loggined in as: {bot.user.name}") 420 | 421 | if __name__ == '__main__': 422 | bot.run("PASTE YOUR TOKEN HERE") 423 | -------------------------------------------------------------------------------- /part2.py: -------------------------------------------------------------------------------- 1 | from nextcord.ext import commands 2 | import requests, json, random 3 | 4 | links = json.load(open("gifs.json")) 5 | 6 | bot = commands.Bot(command_prefix="dog ") 7 | 8 | @bot.command(name="hi") 9 | async def SendMessage(ctx): 10 | await ctx.send('Hello!') 11 | 12 | @bot.command(name="pic") 13 | async def Dog(ctx): 14 | response = requests.get("https://dog.ceo/api/breeds/image") 15 | image_link = response.json()["message"] 16 | await ctx.send(image_link) 17 | 18 | @bot.command(name="gif", aliases=["feed", "play", "sleep"]) 19 | async def Gif(ctx): 20 | await ctx.send(random.choice(links[ctx.invoked_with])) 21 | 22 | @bot.event 23 | async def on_ready(): 24 | print(f"Loggined in as: {bot.user.name}") 25 | 26 | if __name__ == '__main__': 27 | bot.run("PASTE YOUR TOKEN HERE") -------------------------------------------------------------------------------- /part3.py: -------------------------------------------------------------------------------- 1 | from nextcord.ext import commands 2 | import requests, json, random, datetime, asyncio 3 | 4 | links = json.load(open("gifs.json")) 5 | 6 | bot = commands.Bot(command_prefix="dog ") 7 | 8 | @bot.command(name="hi") 9 | async def SendMessage(ctx): 10 | await ctx.send('Hello!') 11 | 12 | @bot.command(name="pic") 13 | async def Dog(ctx): 14 | response = requests.get("https://dog.ceo/api/breeds/image/random") 15 | image_link = response.json()["message"] 16 | await ctx.send(image_link) 17 | 18 | @bot.command(name="gif", aliases=["feed", "play", "sleep"]) 19 | async def Gif(ctx): 20 | await ctx.send(random.choice(links[ctx.invoked_with])) 21 | 22 | async def schedule_daily_message(): 23 | while True: 24 | now = datetime.datetime.now() 25 | then = now+datetime.timedelta(days=1) 26 | # then = now.replace(hour=22, minute=31) 27 | wait_time = (then-now).total_seconds() 28 | await asyncio.sleep(wait_time) 29 | 30 | channel = bot.get_channel(919372924538986576) 31 | 32 | await channel.send("Good morning!!") 33 | await channel.send(random.choice(links["play"])) 34 | 35 | @bot.event 36 | async def on_ready(): 37 | print(f"Loggined in as: {bot.user.name}") 38 | await schedule_daily_message() 39 | 40 | if __name__ == '__main__': 41 | bot.run("PASTE YOUR TOKEN HERE") -------------------------------------------------------------------------------- /part4.py: -------------------------------------------------------------------------------- 1 | from nextcord.ext import commands 2 | import requests, json, random, datetime, asyncio 3 | 4 | links = json.load(open("gifs.json")) 5 | 6 | bot = commands.Bot(command_prefix="dog ") 7 | 8 | @bot.command(name="hi") 9 | async def SendMessage(ctx): 10 | await ctx.send('Hello!') 11 | 12 | @bot.command(name="pic") 13 | async def Dog(ctx): 14 | response = requests.get("https://dog.ceo/api/breeds/image/random") 15 | image_link = response.json()["message"] 16 | await ctx.send(image_link) 17 | 18 | @bot.command(name="gif", aliases=["feed", "play", "sleep"]) 19 | async def Gif(ctx): 20 | await ctx.send(random.choice(links[ctx.invoked_with])) 21 | 22 | 23 | async def schedule_daily_message(h, m, s, msg, channelid): 24 | while True: 25 | now = datetime.datetime.now() 26 | # then = now+datetime.timedelta(days=1) 27 | then = now.replace(hour=h, minute=m, second=s) 28 | if then < now: 29 | then += datetime.timedelta(days=1) 30 | wait_time = (then-now).total_seconds() 31 | await asyncio.sleep(wait_time) 32 | 33 | channel = bot.get_channel(channelid) 34 | 35 | await channel.send(msg) 36 | await channel.send(random.choice(links["play"])) 37 | await asyncio.sleep(1) 38 | 39 | # dog daily "good morning" 8 30 40 | 41 | @bot.command(name="daily") 42 | async def daily(ctx, mystr:str, hour:int, minute:int, second:int): 43 | print(mystr, hour, minute, second) 44 | 45 | if not (0 < hour < 24 and 0 <= minute <= 60 and 0 <= second < 60): 46 | raise commands.BadArgument() 47 | 48 | time = datetime.time(hour, minute, second) 49 | timestr = time.strftime("%I:%M:%S %p") 50 | await ctx.send(f"A daily message will be sent at {timestr} everyday in this channel.\nDaily message:\"{mystr}\"\nConfirm by simply saying: `yes`") 51 | 52 | @daily.error 53 | async def daily_error(ctx, error): 54 | if isinstance(error, commands.BadArgument): 55 | await ctx.send("""Incorrect format. Use the command this way: `dog daily "message" hour minute second`. 56 | For example: `dog daily "good morning" 22 30 0` for a message to be sent at 10:30 everyday""") 57 | 58 | @bot.event 59 | async def on_ready(): 60 | print(f"Loggined in as: {bot.user.name}") 61 | await schedule_daily_message() 62 | 63 | if __name__ == '__main__': 64 | bot.run("PASTE YOUR TOKEN HERE") -------------------------------------------------------------------------------- /part5.py: -------------------------------------------------------------------------------- 1 | from nextcord.ext import commands 2 | import requests, json, random, datetime, asyncio 3 | from PIL import Image, ImageFont, ImageDraw 4 | import textwrap 5 | from nextcord import File 6 | 7 | links = json.load(open("gifs.json")) 8 | 9 | bot = commands.Bot(command_prefix="dog ") 10 | 11 | @bot.command(name="hi") 12 | async def SendMessage(ctx): 13 | await ctx.send('Hello!') 14 | 15 | @bot.command(name="pic") 16 | async def Dog(ctx): 17 | response = requests.get("https://dog.ceo/api/breeds/image/random") 18 | image_link = response.json()["message"] 19 | await ctx.send(image_link) 20 | 21 | @bot.command(name="gif", aliases=["feed", "play", "sleep"]) 22 | async def Gif(ctx): 23 | await ctx.send(random.choice(links[ctx.invoked_with])) 24 | 25 | 26 | async def schedule_daily_message(h, m, s, msg, channelid): 27 | while True: 28 | now = datetime.datetime.now() 29 | # then = now+datetime.timedelta(days=1) 30 | then = now.replace(hour=h, minute=m, second=s) 31 | if then < now: 32 | then += datetime.timedelta(days=1) 33 | wait_time = (then-now).total_seconds() 34 | await asyncio.sleep(wait_time) 35 | 36 | channel = bot.get_channel(channelid) 37 | 38 | await channel.send(msg) 39 | await channel.send(random.choice(links["play"])) 40 | await asyncio.sleep(1) 41 | 42 | # dog daily "good morning" 8 30 43 | 44 | @bot.command(name="daily") 45 | async def daily(ctx, mystr:str, hour:int, minute:int, second:int): 46 | print(mystr, hour, minute, second) 47 | 48 | if not (0 < hour < 24 and 0 <= minute <= 60 and 0 <= second < 60): 49 | raise commands.BadArgument() 50 | 51 | time = datetime.time(hour, minute, second) 52 | timestr = time.strftime("%I:%M:%S %p") 53 | await ctx.send(f"A daily message will be sent at {timestr} everyday in this channel.\nDaily message:\"{mystr}\"\nConfirm by simply saying: `yes`") 54 | 55 | @daily.error 56 | async def daily_error(ctx, error): 57 | if isinstance(error, commands.BadArgument): 58 | await ctx.send("""Incorrect format. Use the command this way: `dog daily "message" hour minute second`. 59 | For example: `dog daily "good morning" 22 30 0` for a message to be sent at 10:30 everyday""") 60 | 61 | # dog speak hello world!! 62 | 63 | @bot.command(name='speak') 64 | async def speak(ctx, *args): 65 | msg = " ".join(args) 66 | font = ImageFont.truetype("PatrickHand-Regular.ttf", 50) 67 | img = Image.open("dog.jpg") 68 | cx, cy = (350, 230) 69 | 70 | lines = textwrap.wrap(msg, width=20) 71 | print(lines) 72 | w, h = font.getsize(msg) 73 | y_offset = (len(lines)*h)/2 74 | y_text = cy-(h/2) - y_offset 75 | 76 | for line in lines: 77 | draw = ImageDraw.Draw(img) 78 | w, h = font.getsize(line) 79 | draw.text((cx-(w/2), y_text), line, (0, 0, 0), font=font) 80 | img.save("dog-edited.jpg") 81 | y_text += h 82 | 83 | with open("dog-edited.jpg", "rb") as f: 84 | img = File(f) 85 | await ctx.channel.send(file=img) 86 | 87 | 88 | @bot.event 89 | async def on_ready(): 90 | print(f"Loggined in as: {bot.user.name}") 91 | # await schedule_daily_message() 92 | 93 | if __name__ == '__main__': 94 | bot.run("PASTE YOUR TOKEN HERE") -------------------------------------------------------------------------------- /part6.py: -------------------------------------------------------------------------------- 1 | from nextcord.ext import commands 2 | import requests, json, random, datetime, asyncio 3 | from PIL import Image, ImageFont, ImageDraw 4 | import textwrap 5 | from nextcord import File, ButtonStyle 6 | from nextcord.ui import Button, View 7 | 8 | links = json.load(open("gifs.json")) 9 | 10 | bot = commands.Bot(command_prefix="dog ") 11 | 12 | @bot.command(name="hi") 13 | async def SendMessage(ctx): 14 | await ctx.send('Hello!') 15 | 16 | @bot.command(name="pic") 17 | async def Dog(ctx): 18 | response = requests.get("https://dog.ceo/api/breeds/image/random") 19 | image_link = response.json()["message"] 20 | await ctx.send(image_link) 21 | 22 | @bot.command(name="gif", aliases=["feed", "play", "sleep"]) 23 | async def Gif(ctx): 24 | await ctx.send(random.choice(links[ctx.invoked_with])) 25 | 26 | 27 | async def schedule_daily_message(h, m, s, msg, channelid): 28 | while True: 29 | now = datetime.datetime.now() 30 | # then = now+datetime.timedelta(days=1) 31 | then = now.replace(hour=h, minute=m, second=s) 32 | if then < now: 33 | then += datetime.timedelta(days=1) 34 | wait_time = (then-now).total_seconds() 35 | await asyncio.sleep(wait_time) 36 | 37 | channel = bot.get_channel(channelid) 38 | 39 | await channel.send(msg) 40 | await channel.send(random.choice(links["play"])) 41 | await asyncio.sleep(1) 42 | 43 | # dog daily "good morning" 8 30 44 | 45 | @bot.command(name="daily") 46 | async def daily(ctx, mystr:str, hour:int, minute:int, second:int): 47 | print(mystr, hour, minute, second) 48 | 49 | if not (0 < hour < 24 and 0 <= minute <= 60 and 0 <= second < 60): 50 | raise commands.BadArgument() 51 | 52 | time = datetime.time(hour, minute, second) 53 | timestr = time.strftime("%I:%M:%S %p") 54 | await ctx.send(f"A daily message will be sent at {timestr} everyday in this channel.\nDaily message:\"{mystr}\"\nConfirm by simply saying: `yes`") 55 | 56 | @daily.error 57 | async def daily_error(ctx, error): 58 | if isinstance(error, commands.BadArgument): 59 | await ctx.send("""Incorrect format. Use the command this way: `dog daily "message" hour minute second`. 60 | For example: `dog daily "good morning" 22 30 0` for a message to be sent at 10:30 everyday""") 61 | 62 | # dog speak hello world!! 63 | 64 | @bot.command(name='speak') 65 | async def speak(ctx, *args): 66 | msg = " ".join(args) 67 | font = ImageFont.truetype("PatrickHand-Regular.ttf", 50) 68 | img = Image.open("dog.jpg") 69 | cx, cy = (350, 230) 70 | 71 | lines = textwrap.wrap(msg, width=20) 72 | print(lines) 73 | w, h = font.getsize(msg) 74 | y_offset = (len(lines)*h)/2 75 | y_text = cy-(h/2) - y_offset 76 | 77 | for line in lines: 78 | draw = ImageDraw.Draw(img) 79 | w, h = font.getsize(line) 80 | draw.text((cx-(w/2), y_text), line, (0, 0, 0), font=font) 81 | img.save("dog-edited.jpg") 82 | y_text += h 83 | 84 | with open("dog-edited.jpg", "rb") as f: 85 | img = File(f) 86 | await ctx.channel.send(file=img) 87 | 88 | 89 | @bot.command(name='support') 90 | async def support(ctx): 91 | hi = Button(label="click me", style=ButtonStyle.blurple) 92 | subscribe = Button(label="subscribe", url="https://www.youtube.com/channel/UCqRLiT8Kv5RVmoNtnshKZwA?sub_confirmation=1") 93 | 94 | async def hi_callback(interaction): 95 | await interaction.response.send_message("Hello!") 96 | 97 | hi.callback = hi_callback 98 | 99 | myview = View(timeout=180) 100 | myview.add_item(hi) 101 | myview.add_item(subscribe) 102 | 103 | await ctx.send("hi", view=myview) 104 | 105 | @bot.event 106 | async def on_ready(): 107 | print(f"Loggined in as: {bot.user.name}") 108 | # await schedule_daily_message() 109 | 110 | if __name__ == '__main__': 111 | bot.run("PASTE YOUR TOKEN HERE") -------------------------------------------------------------------------------- /part9.py: -------------------------------------------------------------------------------- 1 | from matplotlib.pyplot import text 2 | from nextcord.ext import commands 3 | import requests, json, random, datetime, asyncio 4 | from PIL import Image, ImageFont, ImageDraw 5 | import textwrap 6 | from nextcord import File, ButtonStyle, Embed, Color 7 | from nextcord.ui import Button, View 8 | 9 | links = json.load(open("gifs.json")) 10 | helpGuide = json.load(open("help.json")) 11 | 12 | bot = commands.Bot(command_prefix="dog ") 13 | bot.remove_command("help") 14 | 15 | # create help embed using page number and helpGuide 16 | def createHelpEmbed(pageNum=0, inline=False): 17 | pageNum = (pageNum) % len(list(helpGuide)) 18 | pageTitle = list(helpGuide)[pageNum] 19 | embed=Embed(color=0x0080ff, title=pageTitle) 20 | for key, val in helpGuide[pageTitle].items(): 21 | embed.add_field(name=bot.command_prefix+key, value=val, inline=inline) 22 | embed.set_footer(text=f"Page {pageNum+1} of {len(list(helpGuide))}") 23 | return embed 24 | 25 | 26 | @bot.command(name="help") 27 | async def Help(ctx): 28 | currentPage = 0 29 | 30 | # functionality for buttons 31 | 32 | async def next_callback(interaction): 33 | nonlocal currentPage, sent_msg 34 | currentPage += 1 35 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 36 | 37 | async def previous_callback(interaction): 38 | nonlocal currentPage, sent_msg 39 | currentPage -= 1 40 | await sent_msg.edit(embed=createHelpEmbed(pageNum=currentPage), view=myview) 41 | 42 | # add buttons to embed 43 | 44 | previousButton = Button(label="<", style=ButtonStyle.blurple) 45 | nextButton = Button(label=">", style=ButtonStyle.blurple) 46 | previousButton.callback = previous_callback 47 | nextButton.callback = next_callback 48 | 49 | myview = View(timeout=180) 50 | myview.add_item(previousButton) 51 | myview.add_item(nextButton) 52 | 53 | 54 | sent_msg = await ctx.send(embed=createHelpEmbed(currentPage), view=myview) 55 | 56 | # @bot.command(name="help") 57 | # async def Help(ctx): 58 | # embed=Embed(color=0x0080ff, title="Basic Commands") 59 | # embed.add_field(name="dog pic", value="get a cute doggo pic :)", inline=False) 60 | # embed.add_field(name="dog gif", value="get a cute doggo gif :)", inline=False) 61 | # embed.add_field(name="dog play", value="get a cute playing doggo gif :)", inline=False) 62 | # embed.add_field(name="dog sleep", value="get a cute sleepy doggo gif :)", inline=False) 63 | # await ctx.send(embed=embed) 64 | 65 | # https://nextcord.readthedocs.io/en/latest/ext/commands/api.html#nextcord.ext.commands.cooldown 66 | @commands.cooldown(1, 30, commands.BucketType.user) 67 | @bot.command(name="hi") 68 | async def SendMessage(ctx): 69 | await ctx.send('Hello!') 70 | 71 | @commands.cooldown(1, 3, commands.BucketType.user) 72 | @bot.command(name="pic") 73 | async def Dog(ctx): 74 | response = requests.get("https://dog.ceo/api/breeds/image/random") 75 | image_link = response.json()["message"] 76 | await ctx.send(image_link) 77 | 78 | @commands.cooldown(1, 3, commands.BucketType.user) 79 | @bot.command(name="gif", aliases=["feed", "play", "sleep"]) 80 | async def Gif(ctx): 81 | await ctx.send(random.choice(links[ctx.invoked_with])) 82 | 83 | 84 | async def schedule_daily_message(h, m, s, msg, channelid): 85 | while True: 86 | now = datetime.datetime.now() 87 | # then = now+datetime.timedelta(days=1) 88 | then = now.replace(hour=h, minute=m, second=s) 89 | if then < now: 90 | then += datetime.timedelta(days=1) 91 | wait_time = (then-now).total_seconds() 92 | await asyncio.sleep(wait_time) 93 | 94 | channel = bot.get_channel(channelid) 95 | 96 | await channel.send(msg) 97 | await channel.send(random.choice(links["play"])) 98 | await asyncio.sleep(1) 99 | 100 | # dog daily "good morning" 8 30 101 | 102 | @commands.cooldown(1, 20, commands.BucketType.user) 103 | @bot.command(name="daily") 104 | async def daily(ctx, mystr:str, hour:int, minute:int, second:int): 105 | print(mystr, hour, minute, second) 106 | 107 | if not (0 < hour < 24 and 0 <= minute <= 60 and 0 <= second < 60): 108 | raise commands.BadArgument() 109 | 110 | time = datetime.time(hour, minute, second) 111 | timestr = time.strftime("%I:%M:%S %p") 112 | await ctx.send(f"A daily message will be sent at {timestr} everyday in this channel.\nDaily message:\"{mystr}\"\nConfirm by simply saying: `yes`") 113 | 114 | @daily.error 115 | async def daily_error(ctx, error): 116 | if isinstance(error, commands.BadArgument): 117 | await ctx.send("""Incorrect format. Use the command this way: `dog daily "message" hour minute second`. 118 | For example: `dog daily "good morning" 22 30 0` for a message to be sent at 10:30 everyday""") 119 | 120 | # dog speak hello world!! 121 | 122 | @bot.command(name='support') 123 | async def support(ctx, *args): 124 | hi = Button(label="click me", style=ButtonStyle.blurple) 125 | 126 | async def hi_callback(interaction): 127 | await interaction.response.send_message("Hello!!") 128 | 129 | hi.callback = hi_callback 130 | 131 | myview = View(timeout=180) 132 | myview.add_item(hi) 133 | 134 | await ctx.send(f"hi {ctx.message.author.mention}", view=myview) 135 | 136 | @commands.cooldown(1, 5, commands.BucketType.user) 137 | @bot.command(name='speak') 138 | async def speak(ctx, *args): 139 | msg = " ".join(args) 140 | font = ImageFont.truetype("PatrickHand-Regular.ttf", 50) 141 | img = Image.open("dog.jpg") 142 | cx, cy = (350, 230) 143 | 144 | lines = textwrap.wrap(msg, width=20) 145 | print(lines) 146 | w, h = font.getsize(msg) 147 | y_offset = (len(lines)*h)/2 148 | y_text = cy-(h/2) - y_offset 149 | 150 | for line in lines: 151 | draw = ImageDraw.Draw(img) 152 | w, h = font.getsize(line) 153 | draw.text((cx-(w/2), y_text), line, (0, 0, 0), font=font) 154 | img.save("dog-edited.jpg") 155 | y_text += h 156 | 157 | with open("dog-edited.jpg", "rb") as f: 158 | img = File(f) 159 | await ctx.channel.send(file=img) 160 | 161 | 162 | @bot.event 163 | async def on_command_error(ctx, error): 164 | if isinstance(error, commands.CommandOnCooldown): 165 | em = Embed(title=f"Slow it down bro!",description=f"Try again in {error.retry_after:.2f}s.", color=Color.red()) 166 | await ctx.send(embed=em) 167 | 168 | @bot.event 169 | async def on_ready(): 170 | print(f"Loggined in as: {bot.user.name}") 171 | # await schedule_daily_message() 172 | 173 | if __name__ == '__main__': 174 | bot.run("PASTE YOUR TOKEN HERE") -------------------------------------------------------------------------------- /textwrap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dannycademy/nextcord-bot-series/118837f1ce1b02bad3db5b3c0b5aad25526142ff/textwrap --------------------------------------------------------------------------------