Answers for "discord.py client.command"

2

discord.py basic command

#If you havent already install discord.py using pip install discord.py
#Then import discord
#Then Import commands
import discord
from discord.ext import commands
#Create your bot instinct
#With the bot Prefix set to !
#You can change it to your choice
client = commands.Bot(command_prefix='!')
client.remove_command('help')
#This is an event when the bot logs in this help to check if 
#the bot is running correctly
@client.event
async def on_ready():
    print('Logged on as Stars Bot')
#This is a basic commad that returns the bots ping
@client.command()
async def ping(ctx):
    await ctx.send(f'Ping is `{round(client.latency * 1000)}` ms ')
#Change the Your token here with the token found in your discord developer portal
#https://discord.com/developers/applications here is a link 
client.run('Your Token here')
Posted by: Guest on July-12-2021

Python Answers by Framework

Browse Popular Code Answers by Language