Heya! Im currently working on a bot everything is working, but at a command, whenever someone that does not have the permission to do such, it should send the message said in the image. but it does not. If I do have the permission the other embed sends just fine, its not only on this line, its this one and another, please help me. Thanks.
#π discord bot - logging error.
125 messages Β· Page 1 of 1 (latest)
@little locust
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.
this is the second.
its the same but just different commands
i got stuck here
for the last hour
code : py @commands.command() @commands.has_permissions(manage_channels=True) async def logs(self, ctx, log_channel: discord.TextChannel, staff_role: discord.Role): # Check if user has manage_channels permission if not ctx.guild.me.guild_permissions.manage_channels: await ctx.send(":prayer_failed: | I am missing the `manage_channels` permission.") return
since you're using @commands.has_permissions()
then you could use:
# Return a message if a user doesn't have permissions (prefix command)
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You are missing the required permissions to run this command.")
# Slash Command
@client.event
async def on_application_command_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You are missing the required permissions to run this command.")
might vary slightly if you're using discord.py, pycord or something else. this example is based off of nextcord
I do not need / want the slash command.
don't include it then
The code provided goes in your main file, being the same file that you use client.run
for me its not client.run its bot.run
yeah, as I said it varies
you'll have to refer to the documentation relevant to what you're using and alter it accordingly
why would i use client.event? btw, my file is a cog
this doesn't go in the cog
so it goes stragith into the main file?
quick question for you
is the error automatically gonna go to the logging?
like the logging problem
or is it gonna go for every single one
What do you mean?
wdym by that
like
the .event will reply to the command that returned a permission error
I want a error, like said :prayer_failed: | I am missing the `manage_channels` permission. to be only sent to the logs and the deletelogs
you would find the channel, then instead of using await ctx.send you'd use await channelName.send()
channel = bot.get_channel(CHANNEL_ID)
await channel.send("foo")
the await ctx.send will send that message to the same channel that the error occurred. for example, if i tried to use a command that I don't have permissions use in #python-discussion, the bot would send your message in that channel
then you could have a database storing the channel ID of different log channels, along with the server ID
then you'd just fetch the channel ID, find the channel in discord and use await channelName.send("hi")
so i put it right here?
as I said, await ctx.send will send the message in the channel that is being used in
are you having a file per command?
yes, i want that to happend
why
just separate them by categories
that's the idea of cogs
not even java requires so many files
xD
the idea is to categorize commands, not to have a command per class
yeah
cogs can be used for 1 file per command, or a file containing all commands specific to moderating or whatever you want
anyways
i do want the message to be sent in the channel that is being used in
but it is not sending
ok
errors?
no errors
this specific part?
!paste
Pasting large amounts of code
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
i do not really know, im being stuck on this thing for the past hour
if i give u the whole code
can u look around
and see if i did something wrong
.
bet
the way you're doing it is alright, but generally it is more recommended for errors to be dealt with via @bot.event
this is my errors
no errors at all
except the syntax dont mind that
here is the WHOLE logging file
are you wanting the error to show if the user running the command has insufficient permissions, or if the bot has insufficient permissions?
user
because ctx.guild.me refers to the bot
possibly
ctx.author.guild_permissions should work
alr
if not ctx.author.guild_permissions.manage_channels:
alright hold on
let me get one of my tester to try it out
i just got a hella error
Traceback (most recent call last):
File "d:\00 ! I prayer bot\cogs\logging.py", line 1, in <module>
import discord
File "C:\Users\mny\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\__init__.py", line 20, in <module>
import logging
File "d:\00 ! I prayer bot\cogs\logging.py", line 2, in <module>
from discord.ext import commands
File "C:\Users\mny\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\ext\commands\__init__.py", line 11, in <module>
from .bot import *
File "C:\Users\mny\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\ext\commands\bot.py", line 28, in <module>
import asyncio
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\asyncio\base_events.py", line 18, in <module>
import concurrent.futures
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\concurrent\futures\__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\concurrent\futures\_base.py", line 43, in <module> LOGGER = logging.getLogger("concurrent.futures")
^^^^^^^^^^^^^^^^^
AttributeError: partially initialized module 'logging' has no attribute 'getLogger' (most likely due to a circular import)```
nvm i just fixed it
'logging' has no attribute 'getLogger' sums it up
any errors?
nope
should i give my main bot file (dw it doesnt have the token there) and the logging.py file?
so u can see
what the problem is
if you want sure
-
main bot file
https://paste.pythondiscord.com/UNGA -
logging file
https://paste.pythondiscord.com/4QMA
there ye go
personally i don't use an error method like this with ctx.author.guild_permissions
so i'd recommend you use the example i gave above to help you in your main bot file.
this, in my opinion, is the better way of informing the author of permission errors, command cooldown, missing role, user input error etc
i'll have a quick look through
mhm
again, in your logging file, this will be checking the permissions of the bot not the command author/user
if not ctx.guild.me.guild_permissions.manage_channels:
await ctx.send(":prayer_failed: | You are missing the `manage_channels` permission.")
return
but i do be needing that the user
?
oh
well i had it like that this whole time
@inland oak mind dming me and helping me in the discord server with the bot cause someone is keep going afk and i cant test
alright
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.