import discord, config
from discord import utils
class MyClient(discord.Client):
async def on_ready(self):
print(f'Logged on as {self.user}!')
async def on_raw_reaction_add(self, payload):
if payload.message_id == config.POST_ID:
mess = await client.get_channel(payload.channel_id).fetch_message(payload.message_id)
emoji = str(payload.emoji)
if len(payload.member.roles)-1 >= config.MAX_ROLERS_PER_USER:
await mess.remove_reaction(payload.emoji, payload.member)
print(f'[ERROR] Too many roles for user {client.get_user(payload.member.id)}')
return 0
if (emoji in config.ROLES):
role = utils.get(mess.guild.roles, id=config.ROLES.get(emoji))
await payload.member.add_roles(role)
print(f'[SUCCESS] {client.get_user(payload.member.id)} has been granted with role {role}')
else:
print(f'[ERROR] KeyError, no role found for {emoji}')
async def on_raw_reaction_remove(self, payload):
if payload.message_id == config.POST_ID:
mess = await client.get_channel(payload.channel_id).fetch_message(payload.message_id)
emoji = str(payload.emoji)
if (emoji in config.ROLES):
role = utils.get(mess.guild.roles, id=config.ROLES.get(emoji))
guild = client.get_guild(mess.guild.id)
member = guild.get_member(payload.user_id)
await member.remove_roles(role)
print(f'[SUCCESS] {role} has been remove for user {client.get_user(payload.user_id)}')
else:
print(f'[ERROR] KeyError, no role found for {emoji}')
# RUN
intents = discord.Intents.all()
client = MyClient(intents=intents)
client.run(config.TOKEN)
TOKEN = 'токен'
POST_ID = айди_сообщения
ROLES = {
'1️⃣': айди_роли_1,
'2️⃣': айди_роли_2,
'': айди_роли_3
}
EXCROLES = ()
MAX_ROLERS_PER_USER = 3
import discord
from discord.ext import commands
token='****'
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)
greeting_channel_id = 1
console_channel = 2
@bot.event
async def on_ready():
print("Я тут!")
@bot.event
async def on_message(message):
global greeting_channel_id
if message.channel.id == console_channel:
if "/set-welcome-Channel" in message.content:
msg = message.content
msg = msg.split()
if (len(msg)!=2):
channel = bot.get_channel(console_channel)
await channel.send("Команда введена неверно!")
greeting_channel_id = msg[1]
@bot.event
async def on_member_join(member):
gci = greeting_channel_id
channel = bot.get_channel(int(gci))
await channel.send(f"Привет, {member.mention}!")
bot.run(token)
import discord
from discord.ext import commands
token='****'
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)
to_check = [
"User#0000", "User#5437"
]
@bot.event
async def on_ready():
print("Я тут!")
global message
channel = bot.get_channel(айди канала)
message = await channel.send("Сообщение")
@bot.event
async def on_raw_reaction_add(payload):
if (payload.message_id == message.id):
for i in range(len(to_check)):
if (to_check[i] == payload.member):
print(f"Совпадение найдено! ({to_check[i]})")
bot.run(token)
import discord
from discord.ext import commands
token='****'
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='+', intents=intents)
channel_for_entering = 847202767772188713
channel_for_leaving = 847212309494366278
@bot.event
async def on_ready():
print("Я запущен!")
@bot.event
async def on_member_join(member):
channel = bot.get_channel(channel_for_entering)
await channel.send(f"приветствую тебя, {member.mention}, на нашем прекрасном сервере {member.guild}!)")
@bot.event
async def on_member_remove(member):
channel = bot.get_channel(channel_for_leaving)
await channel.send(f"{member.mention}, прощай...ты был прекрасным человеком!")
bot.run(token)