Answer the question
In order to leave comments, you need to log in
Code freezes while waiting for messages in discord.py module, how to solve?
The bot is waiting for new messages in the line
@bot.event
async def on_message(message):
if message.content == ('qq'):
channel = message.channel
await channel.send('здарова')
import discord
import json
import requests
import asyncio
from discord.ext import commands
import discord.utils
TOKEN = 'токен'
bot = commands.Bot(command_prefix='$') # инициализируем бота с префиксом '$'
try:
print('started')
@bot.event
async def on_message(message):
if message.content == ('qq'):
channel = message.channel
await channel.send('здарова')
@bot.command() #разрешаем передавать агрументы
async def пинг(ctx): #создаем асинхронную фунцию бота
await ctx.send('Привет! Я бот Red!') #отправляем обратно аргумент
@bot.command()
async def роли(ctx):
member = ctx.message.author
member_roles = member.roles
await ctx.send(f"{member.mention} список твоих ролей:\n{member_roles}")
@bot.command()
async def ищи(ctx, arg):
response = requests.get('https://some-random-api.ml/img/' + str(arg.lower())) # Get-запрос
json_data = json.loads(response.text) # Извлекаем JSON
embed = discord.Embed(color=0xff9900, title='Изображение:') # Создание Embed'a
embed.set_image(url=json_data['link']) # Устанавливаем картинку Embed'a
await ctx.send(embed=embed) # Отправляем Embed
bot.run(TOKEN)
except Exception as exc:
print(exc)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question