intents = discord.Intents.default()
bot = commands.Bot(command_prefix=Auth.COMMAND_PREFIX, intents=intents, auto_sync_commands=True)
async def embedder(self, ctx):
user = ctx.author
#The get channel part
target_channel = bot.get_channel(1128731013875511316)
if len(ctx.message.attachments) == 0:
await ctx.send("No image attachment found.")
return
image_attachment = ctx.message.attachments[0]
if not image_attachment.url.endswith(('.png', '.jpeg', '.jpg', '.gif')):
await ctx.send("Invalid image format. Only PNG, JPEG, JPG, and GIF images are supported.")
return
embed = discord.Embed()
embed.set_image(url=image_attachment.url)
#The part that throws an error
embed.set_author(name=ctx.author.name, icon_url=user.display_avatar)
await target_channel.send(embed=embed)
#get_channel returns NonType, how can I fix that?
1 messages · Page 1 of 1 (latest)
I get this error instead, when I change get to fetch
It keeps getting odder: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: '_MissingSentinel' object has no attribute 'request'
are you running embedder after on_ready
Yes
full error?
also, if you only want to send a message, you should use partial channel object
instead of fetching the channel
fetching the channel is over the api. which is a slow process
- channel = bot.fetch_channel(123)
+ channel = bot.get_partial_messageable(123)
thats all
Traceback (most recent call last):
File "C:\Users\dimen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 378, in _run_event
await coro(*args, **kwargs)
File "C:\Users\dimen\Desktop\economy-bot-discord.py\economy with MYSQL\cogs\events.py", line 63, in on_command_error
raise error
File "C:\Users\dimen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 347, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\dimen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 950, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\dimen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 187, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: '_MissingSentinel' object has no attribute 'request'
intents = discord.Intents.default()
bot = commands.Bot(command_prefix=Auth.COMMAND_PREFIX, intents=intents, auto_sync_commands=True)
@commands.command(usage="submit to voting")
async def embedder(self, ctx):
user = ctx.author
#The get channel part
target_channel = bot.get_partial_messageable(1128731013875511316)
if len(ctx.message.attachments) == 0:
await ctx.send("No image attachment found.")
return
image_attachment = ctx.message.attachments[0]
if not image_attachment.url.endswith(('.png', '.jpeg', '.jpg', '.gif')):
await ctx.send("Invalid image format. Only PNG, JPEG, JPG, and GIF images are supported.")
return
embed = discord.Embed()
embed.set_image(url=image_attachment.url)
#The part that throws an error
embed.set_author(name=ctx.author.name, icon_url=user.display_avatar)
await target_channel.send(embed=embed)
Here's the new full code
can you show on_command_error
What's that? Apologies for the ignorance, I'm very new to this
Oh nvm ignore that message
Till what line does the code run?
Add a few print lines, or use a debugger
hmm
can you show pip list output
That's a lot, get ready xd
Maybe if you have a code snippet that you know works I can import it and check if it works with me as well
oh wow
you should uninstall these
discordpy-antispam 1.0.3
disnake 2.9.0
disnake-pagination 1.1
and reinstall pycord
also, consider a venv
??
Deinstalled those and reinstalled pycord, same error message 😅
After you uninstalled them, did you reinstall py-cord?
If not, uninstall & reinstall
I did
I'm back at my computer in an hour or so
pip uninstall py-cord -y
pip install py-cord
This must be the programmer equivalent of have you try turning it off and on again lol
Yeah still doesn't work
Exact same error fsr
File "C:\Users\dimen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 178, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\dimen\Desktop\economy-bot-discord.py\economy with MYSQL\cogs\inventory.py", line 95, in embedder
await target_channel.send(embed=embed)
File "C:\Users\dimen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\abc.py", line 1616, in send
data = await state.http.send_message(
File "C:\Users\dimen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\http.py", line 283, in request
async with self.__session.request(
AttributeError: '_MissingSentinel' object has no attribute 'request'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\dimen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 378, in _run_event
await coro(*args, **kwargs)
File "C:\Users\dimen\Desktop\economy-bot-discord.py\economy with MYSQL\cogs\events.py", line 63, in on_command_error
raise error
File "C:\Users\dimen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 347, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\dimen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 950, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\dimen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 187, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: '_MissingSentinel' object has no attribute 'request'``` Here is the entire error again
discord.utils I believe, if that's what you mean
I also get this when printing the target_channel variable, maybe this might help? <discord.channel.PartialMessageable object at 0x00000182FDEDBDF0>
You should be fetching channels by [self.]bot.get_channel(id) with self if you’re using cogs
Like
Channel = bot.get_channel(284848229299494)
That was what I did first
Maybe it'll work now since I uninstalled those other packages, I'll try it out
Nope, still returns None
How do you run the bot?
from modules import bank_funcs, inventory_funcs
from config import Auth
import os
import discord
from pycolorise.colors import *
from discord.ext import commands
intents = discord.Intents.all()
client = commands.Bot(command_prefix=Auth.COMMAND_PREFIX, intents=intents, auto_sync_commands=True)
@client.event
async def on_ready():
await client.change_presence(
status=discord.Status.online,
activity=discord.Game(f"{Auth.COMMAND_PREFIX}help")
)
# if you are using 'discord.py >=v2.0' comment(remove) below code
print(Purple("\nLoading Cogs:"))
for file in os.listdir("./cogs"):
if file.endswith(".py"):
filename = file[:-3]
try:
client.load_extension(f"cogs.{filename}")
print(Blue(f"- {filename} :white_check_mark: "))
except:
print(Blue(f"- {filename} :x: "))
# if you are using 'discord.py >=v2.0' uncomment(add) below code
# print(Purple("\nLoading Cogs:"))
# for file in os.listdir("./cogs"):
# if file.endswith(".py"):
# filename = file[:-3]
# try:
# await client.load_extension(f"cogs.{filename}")
# print(Blue(f"- {filename} :white_check_mark: "))
# except:
# print(Blue(f"- {filename} :x: "))
print()
await inventory_funcs.DB.connect()
if not inventory_funcs.DB.is_connected:
raise RuntimeError("Database access denied")
await bank_funcs.create_table()
await inventory_funcs.create_table()
print(Cyan("Created/modified tables successfully"))
print(Cyan(f"{client.user.name} is online !"))
if __name__ == "__main__":
# Make sure to add Bot Token in '.env' file
client.run(Auth.TOKEN)
``` This is main, the embedder command I made is in the inventory cog
Wait bruh 💀
You made a new variable bot in the cog file
You are supposed to use the one you set in the init of the Cog
See the guide
It has an example
.tag guide
Still returns None 🥲
Show updated cog
Nvm I made a small error, it finally works!
Thank you all everyone for the help 
.solved
This thread was archived by the user that opened it.