Question:
It’s how I import Discord commands.
and I get an error:
"commands" is unknown import symbol
pyright-extended
how can I fix it?
Repl link:
https://replit.com/@krichencat/selenium#main.py
from discord.ext import commands
Question:
It’s how I import Discord commands.
and I get an error:
"commands" is unknown import symbol
pyright-extended
how can I fix it?
Repl link:
https://replit.com/@krichencat/selenium#main.py
from discord.ext import commands
Did you check if discord.py is installed?
Use:
pip show discord.py
To see if discord.py is installed. If nothing shows up you need to install the package.
yes installed 2.3.0
first it was 2.3.2, I thought there was a bug in this version and put 2.3.0 - it didn’t help
Doens’t pyright need a pyrightconfig.json
file to actually work? And you sure you shared the right link to your repl?
maybe I don’t know much about it
all I did was install from the command line, as you showed me.
uninstalled the latest version
pip uninstall discord.py
and downgraded it to 2.3.0.
pip install discord.py==2.3.0
what do I do now?
How to connect the sub pages with the main pages?(HTML, CSS and Java script)
If your code works fine, then there is no problem and you have to tell pyright
that there is no problem explicitly, using a comment.
from discord.ext import commands # type: ignore
I’m pretty sure that repls use pyproject.toml
to configure pyright instead of pyrightconfig.json
, by default.
That’s the thing, the commands don’t work.
I didn’t pay attention to what was highlighted in red at first and was looking for the cause elsewhere.
However, for a simple function, I don’t see any other options.
It’s as if the commands are not imported
@bot.command()
async def delete_message(ctx, message_id: int):
try:
channel = ctx.channel
message = await channel.fetch_message(message_id)
if message:
await message.delete()
print(f'Сообщение с ID {message_id} удалено.'
) # Выводим информацию в консоль
await ctx.send(f'Сообщение с ID {message_id} удалено.')
else:
await ctx.send(f'Сообщение с ID {message_id} не найдено.')
except Exception as e:
await ctx.send(f'Произошла ошибка при удалении сообщения: {e}')
I don’t have any experience with python discord. If you want to make sure that it is imported, put this right after the import:
print(commands)
print("DIR: ", dir(commands))
I can’t offer any more help in this area, but just from a google search, are these related?:
Commands (first warning: message_content
intent)
Frequently Asked Questions (on_message
)
python - discord.py @bot.command() not running - Stack Overflow
That’s right,
there’s none of that in the console
print(commands)
print("DIR: ", dir(commands))
nothing
Is the file that is importing commands
being run?
You can test this with something like:
raise KeyboardInterrupt(commands)
top level in module
Tortured and abandoned)
plugged in slash commands, it works
from discord import app_commands
bot = discord.Client(command_prefix='/', intents=intents)
tree = app_commands.CommandTree(bot)
MY_GUILD_ID = os.environ['MY_GUILD_ID']
@tree.command(guild=discord.Object(id=MY_GUILD_ID))
async def privet(interaction: discord.Interaction):
await interaction.response.send_message("Привет!", ephemeral=False)