#π Error in the code
7 messages Β· Page 1 of 1 (latest)
@inland harbor
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.
Closes after a period of inactivity, or when you send !close.
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}")
I posted the entire code here https://paste.pythondiscord.com/M6GA
which line triggered the error?
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.