-2

Нужно чтобы бот каждые сутки отправлял какое-либо сообщение в определенный канал.

Код для изменения:

from discord.ext import commands


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


@bot.event
async def on_ready():
    print('Bot logged as {}'.format(bot.user))

# Ваше решение
@bot.event
async def on_message(ctx):
    message = get_message()
    await bot.get_channel(********).send(message')

token = '*********************'
bot.run(token)
2
  • 2
    это больше похоже на задание, чем на вопрос) что у вас конкретно не получается?
    – timur
    3 окт 2020 в 13:49
  • @timur у меня не получается автоматизировать отправку сообщений каждые 24 часа, то есть я не понимаю как это сделать.
    – Ratmir
    3 окт 2020 в 18:53

2 ответа 2

0

Попробуйте так:

from discord.ext import commands
import asyncio

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

@bot.event
async def on_ready():
    print('Bot logged as {}'.format(bot.user))


@bot.event
async def on_message(ctx):
    message = get_message()
    await bot.get_channel(********).send(message)
    await asyncio.sleep(86400) # 24 часов это 86400 секунд
    await bot.get_channel(********).send(message)

token = '*********************'
bot.run(token)
0
import asyncio
from discord.ext import commands

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

async def background_task():
      time = 86400
      await asyncio.sleep(time)
      message = get_message()
      await bot.get_channel(********).send(message)

@bot.event
async def on_ready():
    print('Bot logged as {}'.format(bot.user))


@bot.event
async def on_message(ctx):
    pass


token = '*********************'
bot.loop.create_task(background_task())
bot.run(token)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.