Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3.  
  4. client = commands.Bot(command_prefix = '.')
  5.  
  6. @client.event
  7. async def on_ready():
  8. await client.change_presence(status=discord.Status.Online, activity=discord.Game("Roblox"))
  9. print("Bot is ready")
  10.  
  11. @client.event
  12. async def on_member_join(member):
  13. print(f"{member} joined the channel")
  14.  
  15. @client.event
  16. async def on_member_remove(member):
  17. print(f"{member} Left the server")
  18.  
  19. @client.command(aliases=("8ball", "ask"))
  20. async def _8ball(ctx, *, question):
  21. reponses = ("C'est certain",
  22. "Cela ne fait aucun doute",
  23. "Oof,je n'ai pas compris",
  24. "Bien sur",
  25. "Oui",
  26. "J'imagine",)
  27. await ctx.send(f"Question: {question}\nAnswer: {random.choice(responses)}) ")
  28.  
  29. @client.command()
  30. @commands.has_role("Moderateur") or has_role("Fondateur")
  31. async def kick(ctx, member : discord.Member, *, reason=None):
  32. await member.kick(reason=reason)
  33.  
  34. @client.command()
  35. @commands.has_role("Moderateur") or has_role("Fondateur")
  36. async def ban(ctx, member : discord.Member, *, reason=None):
  37. await member.ban(reason=reason)
  38.  
  39. @client.command()
  40. @commands.has_role("Moderateur") or has_role("Fondateur")
  41. async def unban(ctx, *, member):
  42. banned_users = await ctx.guild.bans()
  43. member_name, member_discriminator = member.split("#")
  44.  
  45.  
  46. for ban_entry in banned_users:
  47. user = ban_entry.user
  48.  
  49. if (user.name, user.discriminator) == (member_name, member_discriminator)
  50. await ctx.guild.unban(user)
  51. await ctx.send(f"Unbanned {user.name}#{user.discriminator} ")
  52.  
  53. import discord
  54. from discord.ext import commands
  55.  
  56. client = commands.Bot(command_prefix = '.')
  57.  
  58. @client.event
  59. async def on_ready():
  60. await client.change_presence(status=discord.Status.Online, activity=discord.Game("Roblox"))
  61. print("Bot is ready")
  62.  
  63. @client.event
  64. async def on_member_join(member):
  65. print(f"{member} joined the channel")
  66.  
  67. @client.event
  68. async def on_member_remove(member):
  69. print(f"{member} Left the server")
  70.  
  71. @client.command(aliases=("8ball", "ask"))
  72. async def _8ball(ctx, *, question):
  73. reponses = ("C'est certain",
  74. "Cela ne fait aucun doute",
  75. "Oof,je n'ai pas compris",
  76. "Bien sur",
  77. "Oui",
  78. "J'imagine",)
  79. await ctx.send(f"Question: {question}\nAnswer: {random.choice(responses)}) ")
  80.  
  81. @client.command()
  82. @commands.has_role("Moderateur") or has_role("Fondateur")
  83. async def kick(ctx, member : discord.Member, *, reason=None):
  84. await member.kick(reason=reason)
  85.  
  86. @client.command()
  87. @commands.has_role("Moderateur") or has_role("Fondateur")
  88. async def ban(ctx, member : discord.Member, *, reason=None):
  89. await member.ban(reason=reason)
  90.  
  91. @client.command()
  92. @commands.has_role("Moderateur") or has_role("Fondateur")
  93. async def unban(ctx, *, member):
  94. banned_users = await ctx.guild.bans()
  95. member_name, member_discriminator = member.split("#")
  96.  
  97.  
  98. for ban_entry in banned_users:
  99. user = ban_entry.user
  100.  
  101. if (user.name, user.discriminator) == (member_name, member_discriminator)
  102. await ctx.guild.unban(user)
  103. await ctx.send(f"Unbanned {user.name}#{user.discriminator} ")
  104.  
  105.  
  106. @client.command(pass_context=True, aliases=['join', 'j'])
  107. async def join(ctx):
  108. channel = ctx.message.author.voice.channel
  109. voice = get(bot.voice_clients, guild=ctx.guild)
  110.  
  111. if voice and voice.is_connected():
  112. await voice.move_to(channel)
  113. else:
  114. voice = await channel.connect()
  115.  
  116. await voice.disconnect()
  117.  
  118. if voice and voice.is_connected():
  119. await voice.move_to(channel)
  120. else:
  121. voice = await channel.connect()
  122. print(f"The bot has connected to {channel}\n")
  123.  
  124. await ctx.send(f"Joined {channel}")
  125.  
  126.  
  127. @bot.command(pass_context=True, aliases=['l', 'lea'])
  128. async def leave(ctx):
  129. channel = ctx.message.author.voice.channel
  130. voice = get(bot.voice_clients, guild=ctx.guild)
  131.  
  132. if voice and voice.is_connected():
  133. await voice.disconnect()
  134. print(f"The bot has left {channel}")
  135. await ctx.send(f"Left {channel}")
  136. else:
  137. print("Bot was told to leave voice channel, but was not in one")
  138. await ctx.send("Don't think I am in a voice channel")
  139.  
  140.  
  141. @bot.command(pass_context=True, aliases=['p', 'pla'])
  142. async def play(ctx, url: str):
  143.  
  144. song_there = os.path.isfile("song.mp3")
  145. try:
  146. if song_there:
  147. os.remove("song.mp3")
  148. print("Removed old song file")
  149. except PermissionError:
  150. print("Trying to delete song file, but it's being played")
  151. await ctx.send("ERROR: Music playing")
  152. return
  153.  
  154. await ctx.send("Getting everything ready now")
  155.  
  156. voice = get(bot.voice_clients, guild=ctx.guild)
  157.  
  158. ydl_opts = {
  159. 'format': 'bestaudio/best',
  160. 'postprocessors': [{
  161. 'key': 'FFmpegExtractAudio',
  162. 'preferredcodec': 'mp3',
  163. 'preferredquality': '192',
  164. }],
  165. }
  166.  
  167. with youtube_dl.YoutubeDL(ydl_opts) as ydl:
  168. print("Downloading audio now\n")
  169. ydl.download([url])
  170.  
  171. for file in os.listdir("./"):
  172. if file.endswith(".mp3"):
  173. name = file
  174. print(f"Renamed File: {file}\n")
  175. os.rename(file, "song.mp3")
  176.  
  177. voice.play(discord.FFmpegPCMAudio("song.mp3"), after=lambda e: print("Song done!"))
  178. voice.source = discord.PCMVolumeTransformer(voice.source)
  179. voice.source.volume = 0.07
  180.  
  181. nname = name.rsplit("-", 2)
  182. await ctx.send(f"Playing: {nname[0]}")
  183. print("playing\n")
  184.  
  185.  
  186. client.run("NjAyNDAxOTM1NTk2ODQ3MTA1.XTQVnw.73jFnkA8LT8mFF7IZn0910VTBw8")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement