хелп код

tripxkid

Новичок
Автор темы
10
2
Бот нужен для удаления реакций в дс спустя определённый промежуток времени, но он удаляет для одного пользователя, как сделать многопоточность?

ds:
import discord
from discord.ext import commands
from time import time
from ds import config
import datetime

def get_dates():
    return datetime.datetime.today().replace(microsecond=0)

print('BOT version 0.5 by tripxkid')

bot = commands.Bot(command_prefix='>')

chatid = int(config.chat_id)
time_delete = int(config.time_delete)
time_send = int(config.time_send)

@bot.event
async def on_ready():
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='за шухером'))
    print('Бот запущен: {}'.format(bot.user.name))


@bot.event
async def on_raw_reaction_add(payload):       
        channelid = payload.channel_id
        user = payload.member
        messageid = payload.message_id
        print('============НОВОЕ СООБЩЕНИЕ============')
        print(f'[{(get_dates())}] Чат:{channelid} Пользователь:{user} Id-Сообщения: {messageid}')
        
        if channelid == chatid:
            channel = bot.get_channel(channelid)
            message = await channel.fetch_message(messageid)
            #print(f'MSG:{message}')
        return await test_remove(user,message)


async def on_raw_reaction_remove(payload):
        pritn('[TEST] REMOVE REACTION')
        pass

async def test_remove(user,message):
    #time.sleep(time_send)
    await user.send(f'{user} - {str(config.msg_text)} время [{(get_dates())}]')
    print(f'Напомнил что аренда слетит: {user} [{(get_dates())}]')
    
    time.sleep(time_delete)
    print(f'Удалил реакцию: {user} [{(get_dates())}]')

    for reaction in message.reactions:           
            await reaction.remove(user)
    return

if __name__ == '__main__':
    #Запускаю Бота
    print('Запустил main')
    bot.run(config.token)
 
Решение
Скидывал автору темы в телеграмм, но если кому то нужно - можно использовать данный код
Python:
import discord
import asyncio
import threading
from discord.ext import commands
from time import time
from ds import config
import datetime

def get_dates():
    return datetime.datetime.today().replace(microsecond=0)

print('BOT version 0.5 by tripxkid')

bot = commands.Bot(command_prefix='>')

chatid = int(config.chat_id)
time_delete = int(config.time_delete)
time_send = int(config.time_send)

@bot.event
async def on_ready():
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='за шухером'))
    print('Бот запущен: {}'.format(bot.user.name))

@bot.event
async def on_raw_reaction_add(payload)...

TastyBread123

Известный
609
288
Бот нужен для удаления реакций в дс спустя определённый промежуток времени, но он удаляет для одного пользователя, как сделать многопоточность?

ds:
import discord
from discord.ext import commands
from time import time
from ds import config
import datetime

def get_dates():
    return datetime.datetime.today().replace(microsecond=0)

print('BOT version 0.5 by tripxkid')

bot = commands.Bot(command_prefix='>')

chatid = int(config.chat_id)
time_delete = int(config.time_delete)
time_send = int(config.time_send)

@bot.event
async def on_ready():
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='за шухером'))
    print('Бот запущен: {}'.format(bot.user.name))


@bot.event
async def on_raw_reaction_add(payload):    
        channelid = payload.channel_id
        user = payload.member
        messageid = payload.message_id
        print('============НОВОЕ СООБЩЕНИЕ============')
        print(f'[{(get_dates())}] Чат:{channelid} Пользователь:{user} Id-Сообщения: {messageid}')
     
        if channelid == chatid:
            channel = bot.get_channel(channelid)
            message = await channel.fetch_message(messageid)
            #print(f'MSG:{message}')
        return await test_remove(user,message)


async def on_raw_reaction_remove(payload):
        pritn('[TEST] REMOVE REACTION')
        pass

async def test_remove(user,message):
    #time.sleep(time_send)
    await user.send(f'{user} - {str(config.msg_text)} время [{(get_dates())}]')
    print(f'Напомнил что аренда слетит: {user} [{(get_dates())}]')
 
    time.sleep(time_delete)
    print(f'Удалил реакцию: {user} [{(get_dates())}]')

    for reaction in message.reactions:        
            await reaction.remove(user)
    return

if __name__ == '__main__':
    #Запускаю Бота
    print('Запустил main')
    bot.run(config.token)
Так а что требуется? Удалить все реакции что ли? Если да, то:

Код:
msg_object.clear() #msg_object получается через fetch_message у тебя
 

uqowivad

Участник
5
1
Скидывал автору темы в телеграмм, но если кому то нужно - можно использовать данный код
Python:
import discord
import asyncio
import threading
from discord.ext import commands
from time import time
from ds import config
import datetime

def get_dates():
    return datetime.datetime.today().replace(microsecond=0)

print('BOT version 0.5 by tripxkid')

bot = commands.Bot(command_prefix='>')

chatid = int(config.chat_id)
time_delete = int(config.time_delete)
time_send = int(config.time_send)

@bot.event
async def on_ready():
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='за шухером'))
    print('Бот запущен: {}'.format(bot.user.name))

@bot.event
async def on_raw_reaction_add(payload):
    channelid = payload.channel_id
    user = payload.member
    messageid = payload.message_id
    print('============НОВОЕ СООБЩЕНИЕ============')
    print(f'[{(get_dates())}] Чат:{channelid} Пользователь:{user} Id-Сообщения: {messageid}')
    if channelid == chatid:
        channel = bot.get_channel(channelid)
        message = await channel.fetch_message(messageid)
        asyncio.run_coroutine_threadsafe(test_remove(user, message), bot.loop)

async def test_remove(user, message):
    await asyncio.sleep(time_send)
    await user.send(f'{user} - {str(config.msg_text)} время [{(get_dates())}]')
    print(f'Напомнил что аренда слетит: {user} [{(get_dates())}]')

    await asyncio.sleep(time_delete)
    print(f'Удалил реакцию: {user} [{(get_dates())}]')

    for reaction in message.reactions:
        asyncio.run_coroutine_threadsafe(reaction.remove(user), bot.loop)

if __name__ == '__main__':
    #Запускаю Бота
    print('Запустил main')
    bot.run(config.token)