#πŸ”’ Error in the code

7 messages Β· Page 1 of 1 (latest)

red sonnetBOT
#

@inland harbor

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

inland harbor
#

Hello, I decided to write some code, but when I run it, the logs give me this error when synchronizing slash commands: object NoneType can't be used in 'await' expression. What did I do wrong? Thanks

#
import os
import discord
from discord.ext import commands
from discord import app_commands
from discord import Interaction, Embed
import asyncio
import logging
from typing import Optional
import json

from discord.ui import View, button, Modal, TextInput, Button

# Π€Π°ΠΉΠ» для хранСния Π΄Π°Π½Π½Ρ‹Ρ… ΠΎ администраторах
ADMIN_FILE = "admins.json"

# ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅
bot_prefix = "!"
bot_activity = discord.Activity(type=discord.ActivityType.playing, name="Rust")
bot_status = discord.Status.online
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
intents.reactions = True

# Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ экзСмпляра Π±ΠΎΡ‚Π°
bot = commands.Br.remove_roles(mute_role, reason="БнятиС ΠΌΡƒΡ‚Π° послС истСчСния Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ")
    except discord.Forbidden:
        print(f"НСт ΠΏΡ€Π°Π² Π½Π° ΡƒΠ΄Π°Π»Π΅Π½ΠΈΠ΅ Ρ€ΠΎΠ»ΠΈ Ρƒ {member}")
    except discord.HTTPException as e:
        print(f"Ошибка ΠΏΡ€ΠΈ ΡƒΠ΄Π°Π»Π΅Π½ΠΈΠΈ Ρ€ΠΎΠ»ΠΈ Ρƒ {member}: {e}")

@bot.event
async def on_ready():
    try:
        if bot.guilds:
            for guild in bot.guilds:
                # ΠžΡ‡ΠΈΡΡ‚ΠΊΠ° всСх ΠΊΠΎΠΌΠ°Π½Π΄ Π² Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΌ гильдии
                await bot.tree.clear_commands(guild=guild)
                # ΠŸΠ΅Ρ€Π΅ΡΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΈ синхронизация ΠΊΠΎΠΌΠ°Π½Π΄
                synced = await bot.tree.sync(guild=guild)
                if synced is None:
                    print(f"НС ΡƒΠ΄Π°Π»ΠΎΡΡŒ ΡΠΈΠ½Ρ…Ρ€ΠΎΠ½ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π½Π° сСрвСрС {guild.name}")
                else:
                    print(f"Π‘ΠΈΠ½Ρ…Ρ€ΠΎΠ½ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½ΠΎ ΠΊΠΎΠΌΠ°Π½Π΄ Π½Π° сСрвСрС {guild.name}: {len(synced)}")
        else:
            # ΠŸΠ΅Ρ€Π΅ΡΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΈ синхронизация Π³Π»ΠΎΠ±Π°Π»ΡŒΠ½Ρ‹Ρ… ΠΊΠΎΠΌΠ°Π½Π΄
            synced = await bot.tree.sync()
            if synced is None:
                print("НС ΡƒΠ΄Π°Π»ΠΎΡΡŒ ΡΠΈΠ½Ρ…Ρ€ΠΎΠ½ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Π³Π»ΠΎΠ±Π°Π»ΡŒΠ½Ρ‹Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹.")
            else:
                print(f"Π‘ΠΈΠ½Ρ…Ρ€ΠΎΠ½ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½ΠΎ Π³Π»ΠΎΠ±Π°Π»ΡŒΠ½Ρ‹Ρ… ΠΊΠΎΠΌΠ°Π½Π΄: {len(synced)}")
    except Exception as e:
        print(f"Ошибка ΠΏΡ€ΠΈ синхронизации ΠΊΠΎΠΌΠ°Π½Π΄: {e}")
river stag
#

which line triggered the error?

red sonnetBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.