Проблема с ботом дс

Рейтинг: 0Ответов: 1Опубликовано: 20.02.2023

Код:

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        # don't respond to ourselves
    if message.author == self.user:
        return

    if message.content == 'ping':
        await message.channel.send('pong')

intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)
client.run('token')

ошибка: RuntimeError Traceback (most recent call last) in 16 intents.message_content = True 17 client = MyClient(intents=intents) ---> 18 client.run('token')

1 frames
/usr/lib/python3.8/asyncio/runners.py in run(main, debug)
     31     """
     32     if events._get_running_loop() is not None:
--->     33         raise RuntimeError(
     34             "asyncio.run() cannot be called from a running event loop")
     35 

RuntimeError: asyncio.run() cannot be called from a running event loop

система google colab

Ответы

▲ 0

Вы забыли отступы:

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        # don't respond to ourselves
        if message.author == self.user:
            return
        if message.content == 'ping':
            await message.channel.send('pong')

intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)
client.run('token')