Answers for "discord.py commands"

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
1

Discord.py bot example

#Anything commented out is optional

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='prefix here')

@bot.event
async def on_ready():
#   await bot.change_presence(activity=discord.Game(name="Rich Presence Here"))
    print('Logged in as: ' + bot.user.name)
    print('Ready!\n')
    
@bot.command()
async def commandname(ctx, *, somevariable)
#If you don't need a variable, then you only need (ctx)
#	"""Command description"""
	Code goes here
	await ctx.send('Message')

bot.run('yourtoken')
Posted by: Guest on January-09-2021
0

how to add multiple arguments in discord commands rewrite

@bot.command()
async def args(ctx, arg1, arg2):
    await bot.say('You sent {} and {}'.format(arg1, arg2))
Posted by: Guest on July-07-2020

Python Answers by Framework

Browse Popular Code Answers by Language