import discord import os from dicord.ext import commands, tasks from itertools import cycle client = commands.Bot(command_prefix = '.') status = cycle(['v.Alpha', 'v.Alpha']) @client.event async def on_ready(): await client.change_presence(status=discord.Status.online, activity=discord.Game('Monitoringđź‘€')) change_status.start() print('Bot is ready.') client = commands.Bot @tasks.loop(seconds=10) async def change_status(): await client.change_presence(activity=discord.Game(next(status))) @client.event async def on_member_join(member): print(f'{member} has joined a server.') @client.event async def on_member_remove(member): print(f'{member} has left the server.') @client.commands() async def ping(ctx): await ctx.send(f'Pong! {round(client.latency * 1000)}ms') @client.command(aliases-['8ball', 'test']) async def _8ball(ctx, *, question): responses = ['It is certain.', 'It is decidedly so.', 'Without a doubt.', 'Yes - definitely.', 'You may rely on it.', 'As I see it, yes.', 'Most likely.', 'Outlook good.', 'Yes.', 'Signs point to yes.', 'Reply hazy, try again.', 'Ask again later.', 'Better not tell you now.', 'Cannot predict now.', 'Concentrate and ask again.', "Don't count on it.", 'My reply is no.', 'My sources say no.', 'Outlook not so good.', 'Very doubtful.', await ctx.send(f'Question: {question}\nAnswer: {random.choice(responses)}') @client.command() async def on_message{message}: if message.content == 'coinflip': variable = ['Heads', 'Tails', 'Heads', 'Tails', 'Heads', 'Tails', 'Heads', 'Tails', 'Heads', 'Tails', 'Heads', 'Tails', 'Heads', 'Tails', 'Heads', 'Tails', 'Heads', 'Tails', 'Heads', 'Tails', 'Heads', 'Tails', 'Side'] await client.send_message(messsage.channel(random.choice(variable))) @client.command() async def on_message{message}: if message.content == 'lamerate': variable = ['You are *0%* lame.', 'You are *1%* lame.', 'You are *2%* lame.', 'You are *3%* lame.', 'You are *4%* lame.', 'You are *5%* lame.', 'You are *6%* lame.', 'You are *7%* lame.', 'You are *8%* lame.', 'You are *9%* lame.', 'You are *10%* lame.', 'You are *11%* lame.', 'You are *12%* lame.', 'You are *13%* lame.', 'You are *14%* lame.', 'You are *15%* lame.', 'You are *16%* lame.', 'You are *17%* lame.', 'You are *18%* lame.', 'You are *19%* lame.', 'You are *20%* lame.', 'You are *21%* lame.', 'You are *22%* lame.', 'You are *23%* lame.', 'You are *24%* lame.', 'You are *25%* lame.', 'You are *26%* lame.', 'You are *27%* lame.', 'You are *28%* lame.', 'You are *29%* lame.', 'You are *30%* lame.', 'You are *31%* lame.', 'You are *32%* lame.', 'You are *33%* lame.', 'You are *34%* lame.', 'You are *35%* lame.', 'You are *36%* lame.', 'You are *37%* lame.', 'You are *38%* lame.', 'You are *39%* lame.', 'You are *40%* lame.', 'You are *41%* lame.', 'You are *42%* lame.', 'You are *43%* lame.', 'You are *44%* lame.', 'You are *45%* lame.', 'You are *46%* lame.', 'You are *47%* lame.', 'You are *48%* lame.', 'You are *49%* lame.', 'You are *50%* lame.', 'You are *51%* lame.', 'You are *52%* lame.', 'You are *53%* lame.', 'You are *54%* lame.', 'You are *55%* lame.', 'You are *56%* lame.', 'You are *57%* lame.', 'You are *58%* lame.', 'You are *59%* lame.', 'You are *60%* lame.', 'You are *61%* lame.', 'You are *62%* lame.', 'You are *63%* lame.', 'You are *64%* lame.', 'You are *65%* lame.', 'You are *66%* lame.', 'You are *67%* lame.', 'You are *68%* lame.', 'You are *69%* lame.', 'You are *70%* lame.', 'You are *71%* lame.', 'You are *72%* lame.', 'You are *73%* lame.', 'You are *74%* lame.', 'You are *75%* lame.', 'You are *76%* lame.', 'You are *77%* lame.', 'You are *78%* lame.', 'You are *79%* lame.', 'You are *80%* lame.', 'You are *81%* lame.', 'You are *82%* lame.', 'You are *83%* lame.', 'You are *84%* lame.', 'You are *85%* lame.', 'You are *86%* lame.', 'You are *87%* lame.', 'You are *88%* lame.', 'You are *89%* lame.', 'You are *90%* lame.', 'You are *91%* lame.', 'You are *92%* lame.', 'You are *93%* lame.', 'You are *94%* lame.', 'You are *95%* lame.', 'You are *96%* lame.', 'You are *97%* lame.', 'You are *98%* lame.', 'You are *99%* lame.', 'You are *100%* lame.'] await client.send_message(messsage.channel(random.choice(variable))) @client.event async def on_command_error(ctx, error): if isinstance(error, commands.CommandNotFound): await ctx.send('Invalid command used.') @client.command() @commands.has_permissions(manage_messages=True) async def clear(ctx, amount=int): await ctx.channel.purge(limit=amount) def is_it_me(ctx): return ctx.author.id == @client.commands() @commands.check() async def example(ctx) await ctx.send("Hi I'm {ctx.author}") @clear.error async def clear_error(ctx,error): if instance(error, commands.MissingRequiredArguments): await ctx.send('Please specify an amount of messages to delete.') @client.event async def on_member_join(member): print(f'(member) has joined the server.') @client.event async def on_member_remove(member): print(f'(member) has left the server.') @client.command() async def ping(): @client.commands()async def kick(ctx, member : discord.Member, *, reason=None): @commands.has_permissions(manage_members=True) await member.kick(reason=reason) await ctx.send(f'Kicked {member.mention}') @client.commands()async def ban(ctx, member : discord.Member, *, reason=None): @commands.has_permissions(manage_members=True) await member.ban(reason=reason) await ctx.send(f'Banned {member.mention}') @client.commands() async def unban(ctx, *, member): banned_users = await ctx.guild.bans() member_name, member_disciminator = member.split('#') for ban_entry in banned_users: user ban_entry.user if (user.name, user.discriminator) == (member_name, member_disciminator): await ctx.guild.unban(user) await ctx.send(f'Unbanned {user.mention}') return @client.command() async def load(ctx, extension client.load_extension(f'cogs.{extension}') @client.command() async def unload(ctx, extension client.unload_extension(f'cogs.{extension}') @client.command() async def reload(ctx, extension client.unload_extension(f'cogs.{extension}') client.load_extension(f'cogs.{extension}') for filename in os.listdir('./cogs if filename.endswith('.py'): clinet.load_extension(f'cogs.{filename[:-3]}') client.run('NzE2MTQ2MTE5Nzc5ODExMzM5.XtlJa') Example.py file import discord from discord.ext import commands class Example(commands.Cog): def _init_(self, client): self.client = client #events @commands.Cog.listener() async def on_ready(self): print('Bot is online.') #commands @commands.commands() async def ping(delf, ctx): await ctx.send('Pong!') def setup(client): client.add_cog(Example(client)) Test.py Import discord from discord.ext import commands class Test(commands.Cog def _init_(self, client): self.client = client @commands.commands() async def test(self, ctx): await ctx.send('test') def setup(client): client.add_cog(Test(client)) v0.0.01a
Run
Reset
Share
Import
Link
Embed
Language▼
English
ä¸ć–‡
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question