Skip to content

Instantly share code, notes, and snippets.

@100ze
Last active November 5, 2020 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 100ze/6f75eecfc9a06ae9f268d948a736e73b to your computer and use it in GitHub Desktop.
Save 100ze/6f75eecfc9a06ae9f268d948a736e73b to your computer and use it in GitHub Desktop.
# importando módulos
import os
from dotenv import load_dotenv
from discord.ext import commands
# pegando o token salvo no arquivo .env
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
# definindo o prefixo do bot e armazenando o objeto 'bot'
bot = commands.Bot(command_prefix='!')
# mostrando algo no terminal quando o client se conectar
@bot.event
async def on_ready():
print('{0.user} se conectou com sucesso :)'.format(bot))
# criando comandos
# definindo o nome do comando como 'r' (!r)
@bot.command(name='r')
# recebendo o contexto como 'ctx'
# e o que o usuário digitou após o comando como 'pergunta'
async def oracle_rick(ctx, *, pergunta):
# enviando uma mensagem para o chat
await ctx.send(pergunta)
# repare que usamos o 'await' pois 'ctx.send()' é um método assíncrono
# conectando ao Discord
bot.run(TOKEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment