set discord function python code example
Example 1: discord.py ban
@commands.command()
@commands.has_permissions(ban_members=True)
async def ban(self, ctx, user: discord.Member, *, reason):
await ctx.guild.ban(user, reason=reason)
await user.send(f"You have been banned in {ctx.guild} for {reason}")
await ctx.send(f"{user} has been successfully banned.")
Example 2: How to setup discord.py bot
import discord
from discord.ext import commands
import asyncio
client = commands.Bot(command_prefix='!')
token = 'YOUR TOKEN HERE'
@client.command()
async def hello(ctx):
await ctx.send('Hello I am a Test Bot!')
@client.event
async def on_ready():
print('Hello, I am now running')
client.run(token)