M
M
MadelineTheSlayer2020-11-29 08:21:51
Bots
MadelineTheSlayer, 2020-11-29 08:21:51

How to create a Discord bot that has a chance to temporarily give out a role?

Hello everyone, I need help building a discord bot with just one function.

It should with a certain chance (1-2%) after any user message (in a specific channel) issue a certain role for 2 minutes and then respond to the user that he was sent to the basement.

I am a complete 0 in this case, but the situation is on fire :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Chaka YS, 2020-11-29
@Chaka_1

Well, okay ... Here is my solution, the simplest ... You can twist the probability yourself.

import asyncio
import random
import discord
from discord.ext import commands

intents = discord.Intents.all()

client = commands.Bot(command_prefix='!', intents=intents)

w1 = [0,1,0,0,0,1] #(можешь еще добавить, сколько душе угодно(0, 2, 3, 4... - Не даст роль, 1 - даст роль))
@client.event
async def on_message(message):
    if message.channel != ЗДЕСЬ ID ТВОЕГО "ОПРЕДЕЛЕННОГО" КАНАЛА:
        return
    if message.author == py.user: # (проверка на сообщение от бота(игнорируем))
        return
    w2 = random.choice(w1)
    if w2 == 1:
        guild = message.guild
        channel = message.channel
        user = message.author # (чисто для удобства упрощаем вид)
        await guild.get_member(user.id).add_roles(guild.get_role(А ЗДЕСЬ ID РОЛИ))
        await channel.send('ТЫ ПОПАЛ В ПОДВАЛ, ХА-ХА-ХА')
        await asyncio.sleep(120)

It seems that I don’t see any mistakes, if there are, you will write it here ...
And .. So to speak, for the future. Your question is solved by 2-3 requests to Google .... If it's on, do it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question