Last active
July 12, 2024 20:08
-
-
Save pedroricardo/8db25e8503dbcdbd35a73b48baf556de to your computer and use it in GitHub Desktop.
Criando Bot Para Discord #4 - Adicionar Cargos por Reações [Python] [PT-BR]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
import secreto | |
import asyncio | |
client = discord.Client() | |
COR =0x690FC3 | |
token = secreto.seu_token() | |
msg_id = None | |
msg_user = None | |
@client.event | |
async def on_ready(): | |
print('BOT ONLINE - Olá Mundo!') | |
print(client.user.name) | |
print(client.user.id) | |
print('--------PR-------') | |
@client.event | |
async def on_message(message): | |
if message.content.lower().startswith("!lol"): | |
embed1 =discord.Embed( | |
title="Escolha seu Elo!", | |
color=COR, | |
description="- Bronze = 🐤\n" | |
"- Prata = 📘 \n" | |
"- Ouro = 📙",) | |
botmsg = await client.send_message(message.channel, embed=embed1) | |
await client.add_reaction(botmsg, "🐤") | |
await client.add_reaction(botmsg, "📘") | |
await client.add_reaction(botmsg, "📙") | |
global msg_id | |
msg_id = botmsg.id | |
global msg_user | |
msg_user = message.author | |
@client.event | |
async def on_reaction_add(reaction, user): | |
msg = reaction.message | |
if reaction.emoji == "🐤" and msg.id == msg_id: #and user == msg_user: | |
role = discord.utils.find(lambda r: r.name == "Bronze", msg.server.roles) | |
await client.add_roles(user, role) | |
print("add") | |
if reaction.emoji == "📘" and msg.id == msg_id: #and user == msg_user: | |
role = discord.utils.find(lambda r: r.name == "Prata", msg.server.roles) | |
await client.add_roles(user, role) | |
print("add") | |
if reaction.emoji == "📙" and msg.id == msg_id: #and user == msg_user: | |
role = discord.utils.find(lambda r: r.name == "Ouro", msg.server.roles) | |
await client.add_roles(user, role) | |
print("add") | |
@client.event | |
async def on_reaction_remove(reaction, user): | |
msg = reaction.message | |
if reaction.emoji == "🐤" and msg.id == msg_id: #and user == msg_user: | |
role = discord.utils.find(lambda r: r.name == "Bronze", msg.server.roles) | |
await client.remove_roles(user, role) | |
print("remove") | |
if reaction.emoji == "📘" and msg.id == msg_id: #and user == msg_user: | |
role = discord.utils.find(lambda r: r.name == "Prata", msg.server.roles) | |
await client.remove_roles(user, role) | |
print("remove") | |
if reaction.emoji == "📙" and msg.id == msg_id: #and user == msg_user: | |
role = discord.utils.find(lambda r: r.name == "Ouro", msg.server.roles) | |
await client.remove_roles(user, role) | |
print("remove") | |
client.run(token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def seu_token(): | |
return "xxxxxxxx" | |
#Subistitua xxxxxx pelo seu token!! |
Gostaria de marcar um cargo fora do embed so que no mesmo comando tem alguma dica ?
quando clico no emoji não esta add o cargo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
o código tem vários erros. até tentei arrumar, mas sou leiga na área e acabei embolando tudo. de todos os outros códigos, esse foi o mais fácil de entender a lógica, mas não quer dizer que foi o mais prático.
`import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="!") #definir o prefixo
COR= 0xf109e9 #cor em html
@bot.event # bot entrar online
async def on_ready():
print("BOT ONLINE - Vam bora sô!")
print(bot.user.name)
print(bot.user.id)
print("-----------pp-----------")
@bot.command() # definimos o comando
async def ola(ctx): # aqui definimos o comando e quando digitarmos "!ola" o bot vai responder
msg = 'olá mundo' # criamos uma váriavel para mandar a msg
await ctx.send(msg)
@bot.command()
async def embed(ctx): #criando o embed, o nome do comando será !embed
embed = discord.Embedembed=discord.Embed(
title="Escolha seu Elo!",
color=COR,
description="- Bronze = 🐤\n"
"- Prata = 📘 \n"
"- Ouro = 📙",)