Top.Mail.Ru
Ответы

Как сделать статус? Проблема discord bot python

123456789101112131415161718
 import discord
from discord.bot import Bot
from discord.ext import commands
from discord.ext.commands import

await Bot.change_presence(status=discord.Status.online, activity=discord.Game("роблакс"))

intents = discord.Intents.default()
intents.message_content = True

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

@bot.command()
async def hi(ctx):
    await ctx.send('Привет! <a:cath1:1247096907528929320>')


bot.run('мой токен бота') 

Всё вроде правильно, но выдаёт такую ошибку:

File "C:\Users\Minuimen\Desktop\Mysor\botik\main.py", line 5
await Bot.change_presence(status= discord.Status.online , activity= discord.Game ("роблакс"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: 'await' outside function

По дате
По рейтингу
Аватар пользователя
Ученик

Ошибка вроде указывает на то, что "await"может быть только в "async def". И ещё есть лишние импорты, я их убрал. Вот обновлённый код:

12345678910111213141516171819202122
 import discord 
from discord.ext import commands 
 
# Этот код не работает 
#await Bot.change_presence(status=discord.Status.online, activity=discord.Game("роблакс")) 
 
intents = discord.Intents.default() 
intents.message_content = True 
 
bot = commands.Bot(command_prefix='!', intents=intents) 
 
# Рабочий код 
@bot.event 
async def on_ready(): 
    print("Бот готов!") 
    await bot.change_presence(status=discord.Status.online, activity=discord.Game("роблакс")) 
 
@bot.command() 
async def hi(ctx): 
    await ctx.send('Привет! <a:cath1:1247096907528929320>') 
 
bot.run('Твой токен') 

Если что-то не так, пиши

Аватар пользователя
Ученик

Здравствуйте, удалите :


1
 await Bot.change_presence(status=discord.Status.online, activity=discord.Game("роблакс"))  

И вставьте вот это:

1234
 @bot.event 
async def on_ready():
    await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="spidernodes.space")) 
 
Аватар пользователя
Оракул

Поставь строку с статусом немного ниже

Аватар пользователя
Искусственный Интеллект

Вот ТУТ спроси