#General Help
1 messages ยท Page 3 of 1
Yes but it will not change that when I receive a channel it does not return none
If manage channels is not on, I don't think the bot can see the channel, thus why it's None
I could be wrong
manage channels does not let people see channels regardless of permissions
only administrator does
But on the other commands it works fine...
Wait, so if you get_channel (the one you're trying to get) outside of your model it works?
Yes
I see
In the class it does not work
I replicated it, and it works fine
class Graphisme(discord.ui.Modal):
def __init__(self):
super().__init__("Tu recherches un graphiste ?")
self.add_item(discord.ui.InputText(label="Description :", placeholder ="Entrer une courte description de ce que vous recherchez.", style=discord.InputTextStyle.long))
self.add_item(discord.ui.InputText(label="Budget :", placeholder ="Entrer votre budget."))
async def callback(self, interaction: discord.Interaction):
user = interaction.user
embed = discord.Embed(color=0x2f3136, description=
f":coc_arrow: **{user.name} recherche un graphiste !**\n\n" +
"> :coc_message: **ยป Description :**\n" +
f"{self.children[0].value}\n" +
"> :coc_message: **ยป Budget :**\n"
f"{self.children[1].value}\n"
)
embed.set_thumbnail(url=user.avatar)
embed.set_image(url="https://i.ibb.co/RctGDPz/barrejaunecoc.png")
button_contacter = discord.ui.Button(label="Contacter", style=discord.ButtonStyle.green)
viewGraph = discord.ui.View(timeout=None)
viewGraph.add_item(button_contacter)
channel = client.get_channel(your_channel)
await channel.send(embed=embed, view=viewGraph)
Can you send me all the cogs code ?
I added it to a button in my own bot
bot = discord.Bot(intents=discord.Intents.default())
and I'm not using cogs
That's probably why it works then.
modal = Graphisme()
await interaction.response.send_modal(modal)
This was in a button callback
That's what I did
I'm not familiar with cogs and how they differ from a standard bot, sorry
thanks anyway
Getting Error 405'd when trying to run a command; is that an error on my end or Pycord's end?
You should be safe to ignore it discord released permissions V2 without telling pycord to be prepared so the devs are working on finishing Permissions V2. Your bot should still work, just wont be bale to use perms v2 yet.
The command doesn't run properly; do I just have to wait for the update?
Pinging for visibility, see above message.
Is there an easy way to see if a message has a thread attached to it?
What do you mean by run properly? Does it not show up in the list after typing / or it just dosent respond?
@violet night
On one instance, the first, and on another instance, the second.
Pinging for visibility.
I did not change the code at all between these two instances.
There has been a lot of registration bugs recently. Could you go to your server interactions tab and see if the commands are synced?
Updating pycord to master might also fix this. I think there was a fix implemented
whats the issue here?
There commands are not registering sometimes
it takes time to register
Commands aren't synced
guild command, should be instant
it is a slash command, but it's registered as a guild command so it registers instantly
Are you using debug guilds with one guild ID?
I'm using my personal guild to debug, as far as I know it only has one ID.
Do you define it as a debug guild in the bot constructor or in the command decorator?
I don't, how do I go about that?
So how are you registering the command as a guild command?
class MakeAnAccount(commands.Cog):
def __init__ (self, bot):
self.bot = Bot
self.registry = []
@discord.commands.command(guild_ids=[532672466255085598])
async def register(self, ctx, username):
new_user = Account(ctx.author.id, username)
self.registry.append(new_user)
print("Registered!")
Hmmm. I think it might just be a bug with registration. Someone else might have more information, but I dont have anything else to try sorry :/
Uh, add a response, see if it still errors?
Command currently isn't registering (guild command so should do almost instantly), I'll give it a couple of minutes.
You can add debug_guilds=[guild_id] to your bot init to help make them instant while deving
Did that, command still doesn't register and integrate
I looked at some docs, they are using @commands.command()
Changed it, still doesn't register and integrate.
Has it ever shown up?
It showed up once with the code above, got 405'd when trying to run the command, and then didn't show up again when I rebooted the bot.
hi
Are you running it with /
so the terminal said bot online but when i look in my server the bot isnt ๐
I don't understand the question, sorry
is your command a slash command
is what he's asking
Alright 1 sec
and the one time it did register it appeared as a slash command
from discord.commands import slash_command
then use
@slash_command()
async def register(self, ctx, username):TypeError: slash_command() takes 0 positional arguments but 1 was given
Yo how do I get the content of the first message in a thread
Oh yeah, you're missing the option 1 sec
nevermind, fixed that error, still nothing.
@violet night
@slash_command(guild_ids=[532672466255085598], name="Register", description="")
@option("username", str, description="Username", required=True)
async def register(ctx, username: str):
need self as an argument in register because I need to save the input on the command to an array.
The input would be username?
also
Oh I see
@option("username", str, description="Username", required=True)NameError: name 'option' is not defined
import option with the slash_command
Anyone know why I'm getting this error even though my bot works exactly as expected? I can provide code if I need to
Lots of people getting 405'd atm, likely to do with the permissions v2 update
from discord.commands import slash_command, option
no need to worry
You could get rid of it by upgrading to the master branch
How does one go about upgrading to the master branch? I'd like to see if this fixes my issue.
#969580926885580801 message
pip install git+https://github.com/Pycord-Development/pycord
Hi, I seem to have run to an issue and I am unsure if it has to do with the new discord v2 permissions .
It seems that my bot is completely ignoring discord channel permissions. I've gone as far as removing all permissions, however bot is still able to respond to commands. Any help will be greatly appreciated
@client.slash_command(guild_ids=servers, name="config logchannel")
async def logchannelset(ctx, channel):
c.execute(f'select logchannel from configuration where serverid = {ctx.guild.id}')
exists = c.fetchone()
if exists is None:
c.execute(f'insert into configuration(logchannel) values (?) where serverid = {ctx.guild.id}', (channel.id))
conn.commit()
setEmbed = discord.Embed(title="Configuration Changed", description=f"Configuration for Log Channel has changed.", color=0x008080)
setEmbed.add_field(name="Log Channel Set", value=channel, inline=True)
setEmbed.set_author(name=ctx.interaction.user)
await ctx.interaction.response.send_message(embed=setEmbed)
else:
setEmbed = discord.Embed(title="Configuration Exists", description="A configuration exists for Log Channel", color=0x008080)
logchan = client.get_channel(exists)
logchan = logchan.mention
setEmbed.add_field(name="Log Channel Configuration", value=logchan)
setEmbed.set_author(name=ctx.interaction.user)
await ctx.interaction.response.send_message(embed=setEmbed)
Can anyone possibly help me with this ValidationError occurring in my ```py
async def logchannelset(ctx, channel):
Edit: I've tried searching online and trying to find it on my own, I couldn't find anything that helped me, so here I am.
@violet night I just had success with this
@slash_command()
async def register(self, interaction: discord.Interaction, username: str):
you cant have spaces in slash commands
if you want to achieve that you need to use groups
Ah yeah, forgot about that ๐ฅฒ
Can I grab the ID of the person who put in the command with those arguments?
Still nothing. Giving it a couple of minutes.
No success here.
is there a way to check if channel has slowmode?
slowmode_delay
0 is disabled
Sure
Thanks
@violet night I forgot to tell you, self.bot = bot yours has a B
How can I add description to the slash command options?
do bots need a specific perm to create slash commands
@option("option", discord.SlashCommandOptionType.user, description="Cadet", required=True)
yes, it's an integration permission
Is there a way to embed a videofile in pycord?
just send it
embed = discord.Embed(
title = ...
color = discord.Color.red()
)
Am i limited only to the inbuilt discord.Color colors? How do i use other colors?
for example, i want this to be the embed color
how would i manage that?
get the hex code
color = <hex code>
for example 0xFFFFFF would be white
that would work?
yes
correct, otherwise you'd create an inline comment
ye, thanks
i want it in a discord.Embed not as file
F
The hex code of a color im using is this - b0e4a4
Do i add a 0x in front of it? What does the 0x do?
adding 0x makes it a hexadecimal integer iirc
thank you for the information
no problem
It seems delete_after does not work on a hidden interaction response ๐
How do I change the order of the itens on a desired row? I have added some itens with the decorators and also with the self.addmethod on the view constructor. The issue is that the itens added through the decorator are added first and I haven't found a way to change the order.
Could you show your code please, I got lost
Hmm, so you're creating a View() with buttons
on a single row
i want that hitbox button moved to the left
between "back to move selection" and โถ๏ธ
as I said, the issue is that the hitbox button is added with self.add
while the others use the decorator
Right I see
I haven't found an option on the pycord API reference that allows me to change that order
I don't think you can
is there no insert_item method?
there isn't
I have never done it before, but I think it's just depending on the order you add them to the list
Eg. like here: https://github.com/Pycord-Development/pycord/blob/master/examples/views/paginator.py#L108
examples/views/paginator.py line 108
"""Demonstrates how to pass a list of custom buttons when creating the Paginator instance."""```
it looks like view.children is mutable so i'll try rearenging that
but I thought pycord would have a simple method to do that
๐
whenever I reload my bot, my pre-existing buttons stop working, anyway to prevent this?
not easily, on bot load you would have to find the message, get the buttons and re-add the listeners.
yeah that works but it's really messy
self.children.append(self.children[-2])
self.children.pop(-3)
#971833232574271540 if yall can help 3>
What do you mean by listeners? I could do the rest but not sure what you mean by that
You could make the buttons the same, then self.add_item them as well
Actually found something that may help https://guide.pycord.dev/interactions/ui-components/buttons#persistent-views
Learn all about implementing buttons in your Discord Bot using Pycord.
ooh perfect thanks
I like the idea, if you want you can fill a feature request on the repo
how do we edit a forum's title if the problem is solved?
I'm having some trouble getting a user's banner, is it possible? it seems like it behaves differently than getting an avatar
i've tried:
await ctx.respond(ctx.author.banner.url)
but i just get:
AttributeError: 'NoneType' object has no attribute 'url'
user don't have a banner then
nvm
you need to fetch him (aka api call) to get this info
hi, sorry to bother but i get this error:
ImportError: cannot import name 'bridge' from 'discord.ext' (unknown location)```
I recently switched to pycord and i want to start using the bridge extension but whatever i do i get this error, i install, uninstall and reinstall pycord etc (and discord.py its uninstalled)
||english is not my native spanish, sorry for the orthography errors||
also the version i using of pycord is 1.7.3
a okey, thanks
and a last question...
how do i expect an error whit bridge extension?
because when i use @purge.error to expect an error in a cog y get this when i try to run it:
@purge.error
AttributeError: 'BridgeCommand' object has no attribute 'error'
bot = commands.Bot(command_prefix='$', case_insensitive=True, intents=intents)
now = datetime.datetime.now()
column = -1
number = 0000
active_op = False
attend = 1111
id_num = 00
row = 4
class MyModal(Modal):
def __init__(self) -> None:
super().__init__("Operation Attendance Code")
self.add_item(InputText(label="Attendance Code", placeholder="0000", min_length=4, max_length=4))
self.add_item(InputText(label="ID Number", placeholder="0000", max_length=2))
async def callback(self, interaction: discord.Interaction):
global attend
global column
global row
global number
id_column = column + 1
attend = self.children[0].value
id_num = self.children[1].value
#correct_code = False
if attend == number:
embed = discord.Embed(title="Your Modal Results", color=discord.Color.random())
embed.add_field(name="First Input", value=self.children[0].value, inline=False)
embed.add_field(name="second Input", value=self.children[1].value, inline=False)
worksheet = sh.sheet1
worksheet.update_cell(row, column, attend)
worksheet.update_cell(row, id_column, id_num)
else:
embed = discord.Embed(title="Incorrect Code", color=discord.Color.random())
await interaction.response.send_message(embeds=[embed])
I have a discord bot, when they enter a code into the modal, if the code is correct, it should log the data into a spreadsheet, if they enter the wrong code, tehn it should tell them in an embed. but they way i have it, if they get the code correct, it tells them that the code is incorrect and doesnt log it.
i know its an issue with the if statement but i cant seem to figure out what
the value of an InputText object will be a string and 0000 doesn't equal "0000"
you could either convert the correct code you're storing to a string or do int(self.children[0].value)
you'll have to make sure the value is numeric before doing int(self.children[0].value) as well
Anyone have any experience with Tortoise ORM here?
i tried this and it still isnt working
is it because i have my .env in a .gitignore folder?
eee that fixed it
anyone here knew how to make persistent buttons but in cogs?
@bot.event
async def on_ready():
bot.add_view(MyView()) # Registers a View for persistent listening
class MyView(discord.ui.View):
def __init__(self):
super().__init__(timeout=None) # timeout of the view must be set to None
@discord.ui.button(label="A button", custom_id="button-1", style=discord.ButtonStyle.primary, emoji="๐") # the button has a custom_id set
async def button_callback(self, button, interaction):
await interaction.response.send_message("Button was pressed", ephemeral=True)
@bot.command()
async def button(ctx):
await ctx.send(f"Press the button! View persistence status: {MyView.is_persistent(MyView())}", view=MyView())
this but in cogs, this code is supposed to be persistent that even after the bot restarts you would still be able to interact with the buttons.
I used this same code but put it inside a cog and when I restarted the bot, the interaction failed which should not happen
nvm found a way
- move the
MyViewclass to the main script - add the
bot.add_view(MyView())inside theasync def on_ready(): - import the
MyViewclass on the cog file from main - use the
MyViewclass in the cog
Replit: Updating package configuration
--> python3 -m poetry install
/home/runner/sir-aramis/venv/bin/python3: No module named poetry.main; 'poetry' is a package and cannot be directly executed
exit status 1
Replit: Package operation failed.
why did i get this im using replit btw
Replit: Updating package configuration
--> python3 -m poetry install
/home/runner/sir-aramis/venv/bin/python3: No module named poetry.__main__; 'poetry' is a package and cannot be directly executed
exit status 1
Replit: Package operation failed.
try forking one of your older projects
!install
Install pycord:
pip install py-cord```
Install pycord beta:
```pip uninstall discord.py
pip install py-cord==2.0.0b5```
Install pycord alpha from git:
```pip uninstall discord.py
pip install git+https://github.com/Pycord-Development/pycord```
python3 -m pip install poetry try this @brazen hill
06.05 03:13:54 [Bot] File "/cogs/events.py", line 23, in on_member_join
06.05 03:13:54 [Bot] guild = self.client.get_guild(id=mpGuild)
06.05 03:13:54 [Bot] TypeError: get_guild() got some positional-only arguments passed as keyword arguments: 'id'```
Works in discord.py but in PyCord it's broken. I'm not worried just curious why?
try to remode the id= and
try guild = client.get_guild(mpGuild)
mpGuild must be an int
see if this would work
Yeah just did that assuming it's the positional arguments thingy haha
did it work?
Yeah.
I'm pretty sure PyCord positional arguments is just different than d.py
Never the less working as it should ๐
it is different at some point but has many similarities since pycord is a fork
Replit: Updating package configuration
--> python3 -m poetry install
Traceback (most recent call last):
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/main.py", line 5, in <module>
from .console import main
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/console/init.py", line 1, in <module>
from .application import Application
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/console/application.py", line 7, in <module>
from .commands.about import AboutCommand
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/console/commands/init.py", line 2, in <module>
from .add import AddCommand
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/console/commands/add.py", line 8, in <module>
from .init import InitCommand
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/console/commands/init.py", line 14, in <module>
from tomlkit import inline_table
ImportError: cannot import name 'inline_table' from 'tomlkit' (unknown location)
exit status 1
just try pip install poetry
i did
Looking in indexes: https://package-proxy.replit.com/pypi/simple/
Requirement already satisfied: poetry in ./venv/lib/python3.8/site-packages (1.1.13)
Requirement already satisfied: crashtest<0.4.0,>=0.3.0 in ./venv/lib/python3.8/site-packages (from poetry) (0.3.1)
Requirement already satisfied: packaging<21.0,>=20.4 in ./venv/lib/python3.8/site-packages (from poetry) (20.9)
Requirement already satisfied: pexpect<5.0.0,>=4.7.0 in ./venv/lib/python3.8/site-packages (from poetry) (4.8.0)
Requirement already satisfied: tomlkit<1.0.0,>=0.7.0 in ./venv/lib/python3.8/site-packages (from poetry) (0.10.2)
Requirement already satisfied: cachecontrol[filecache]<0.13.0,>=0.12.9 in ./venv/lib/python3.8/site-packages (from poetry) (0.12.11)
Requirement already satisfied: keyring>=21.2.0 in ./venv/lib/python3.8/site-packages (from poetry) (23.5.0)
Requirement already satisfied: shellingham<2.0,>=1.1 in ./venv/lib/python3.8/site-packages (from poetry) (1.4.0)
Requirement already satisfied: poetry-core<1.1.0,>=1.0.7 in ./venv/lib/python3.8/site-packages (from poetry) (1.0.8)
Requirement already satisfied: requests-toolbelt<0.10.0,>=0.9.1 in ./venv/lib/python3.8/site-packages (from poetry) (0.9.1)
Requirement already satisfied: pkginfo<2.0,>=1.4 in ./venv/lib/python3.8/site-packages (from poetry) (1.8.2)
Requirement already satisfied: clikit<0.7.0,>=0.6.2 in ./venv/lib/python3.8/site-packages (from poetry) (0.6.2)
Requirement already satisfied: html5lib<2.0,>=1.0 in ./venv/lib/python3.8/site-packages (from poetry) (1.1)
Requirement already satisfied: requests<3.0,>=2.18 in ./venv/lib/python3.8/site-packages (from poetry) (2.27.1)
Requirement already satisfied: virtualenv<21.0.0,>=20.0.26 in ./venv/lib/python3.8/site-packages (from poetry) (20.14.1)
Requirement already satisfied: cachy<0.4.0,>=0.3.0 in ./venv/lib/python3.8/site-packages (from poetry) (0.3.0)
Requirement already satisfied: cleo<0.9.0,>=0.8.1 in ./venv/lib/python3.8/site-packages (from poetry) (0.8.1)
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/home/runner/sir-aramis/venv/lib/python3.8/site-packages/CacheControl-0.12.11.dist-info/METADATA'
hmmm
Traceback (most recent call last):
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/main.py", line 5, in <module>
from .console import main
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/console/init.py", line 1, in <module>
from .application import Application
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/console/application.py", line 7, in <module>
from .commands.about import AboutCommand
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/console/commands/init.py", line 2, in <module>
from .add import AddCommand
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/console/commands/add.py", line 8, in <module>
from .init import InitCommand
File "/home/runner/sir-aramis/venv/lib/python3.8/site-packages/poetry/console/commands/init.py", line 14, in <module>
from tomlkit import inline_table
ImportError: cannot import name 'inline_table' from 'tomlkit' (unknown location)
try this
ok?
cause i don't know much about poetry ๐
...
emm
i think that still doesnt work ...
error: /usr/bin/env: โ./python3โ: No such file or directory
Is specifying a debug guild in the bot constructor sufficient to set all my commands as guild specific?
yes
If I wanted to add some functions into the 'discord'(py-cord) namespace, is creating the package 'discord' in my own project sufficient or will that cause errors
any package you create will replace rather than merge
does anyone know if there is a name for this sort of thing, because I swear ruby merged, and while I know this isn't ruby, the concept/name usage should still exist
#972027353029046315
What are you trying to do with this?
cant get message with id, it alway return None
test = self.bot.get_message(972019839013105724)
print(test)
The channel where that message is, is your bot in the user side panel
Yes
actually, you should need an await on that
then i get an error
Could you give me more, I need more context to what self is
Ignoring exception in modal <cogs.survey.SurveyModal object at 0x000001CE7C5B7850>:
Traceback (most recent call last):
File "C:\Users\witti\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ui\modal.py", line 245, in dispatch
await value.callback(interaction)
File "C:\Users\witti\OneDrive\Dokumente\Icons\Programmieren\PycharmProjects\ASTR0-Bot\cogs\survey.py", line 126, in callback
test = await self.bot.get_message(972019839013105724)
TypeError: object NoneType can't be used in 'await' expression
Ah it's a cog
yes
i save the message id in a database and want to get the Object... it dont work
and now with only the id it wont work too
How are you running it, is it inside an interaction?
yes, inside a modal now for test, but before it was inside a task
you can use interaction.client.get_message()
I could be wrong, but I think cog bot's are limited in what they can get
test = interaction.client.get_message(972019839013105724)
print(test)
None
Alright give more code, something must be up
@button(label="1 Agree", style=ButtonStyle.green, emoji="โ
", custom_id="test")
async def agree(self, _button: Button, interaction: Interaction):
"""
:param _button:
:param interaction:
"""
test = interaction.client.get_message(972043628786638888)
print(test)
That should work fine
Are you using intents?
maybe try fetching the message
Intents all
how?
fetch_message()
just change get to fetch
Your bot def has perms to read msgs?
Ignoring exception in view <PersistentView timeout=None children=2> for item <Button style=<ButtonStyle.success: 3> url=None disabled=False label='1 Agree' emoji=<PartialEmoji animated=False name='โ
' id=None> row=None>:
Traceback (most recent call last):
File "C:\Users\witti\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ui\view.py", line 371, in _scheduled_task
await item.callback(interaction)
File "C:\Users\witti\OneDrive\Dokumente\Icons\Programmieren\PycharmProjects\ASTR0-Bot\cogs\survey.py", line 75, in agree
test = self.bot.fetch_message(972043628786638888)
AttributeError: 'Bot' object has no attribute 'fetch_message'
yes
Does AutoComplete have a limit? I have a list of 41 items that I want to autocomplete, but it only shows 30 or so
25
async def test(ctx):
role = get(ctx.guild.roles, id=964563688747069460)
await ctx.author.add_roles(role, reason="Test")```
Anyone know what's wrong here? `get` (imported from discord.Utils):
```Ignoring exception in command test:
Traceback (most recent call last):
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 110, in wrapped
ret = await coro(arg)
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 774, in _invoke
await self.callback(ctx, **kwargs)
File "C:\Users\zakye\Desktop\ใ
คใ
ค\Freelance\DomingoxSita\DomingoxSita_Bot\main.py", line 140, in test
await ctx.author.add_roles(role, reason="Test")
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\member.py", line 950, in add_roles
await req(guild_id, user_id, role.id, reason=reason)
AttributeError: 'coroutine' object has no attribute 'id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py", line 768, in process_application_commands
await ctx.command.invoke(ctx)
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 306, in invoke
await injected(ctx)
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 116, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.commands.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'coroutine' object has no attribute 'id'
C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py:80: RuntimeWarning: coroutine 'ApplicationCommand.__call__' was never awaited
self._context.run(self._callback, *self._args)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
If I use await on the get I get a new error:
Traceback (most recent call last):
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 110, in wrapped
ret = await coro(arg)
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 774, in _invoke
await self.callback(ctx, **kwargs)
File "C:\Users\zakye\Desktop\ใ
คใ
ค\Freelance\DomingoxSita\DomingoxSita_Bot\main.py", line 139, in test
role = await get(ctx.guild.roles, id=964563688747069460)
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 191, in __call__
return await self.callback(ctx, *args, **kwargs)
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 198, in callback
return self._callback
AttributeError: 'SlashCommandGroup' object has no attribute '_callback'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py", line 768, in process_application_commands
await ctx.command.invoke(ctx)
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 306, in invoke
await injected(ctx)
File "C:\Users\zakye\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 116, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.commands.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'SlashCommandGroup' object has no attribute '_callback'```
Found the error seems to occur after I've created a slash command group like this get = client.create_group("get", "Get command") , don't know how this is related though
try to include the arg name like name= and description=
Not sure what you mean, can you provide an example
do you mean in the slash command decorator
get = client.create_group(name="get", description="Get command")
@rigid sandal
also i would try to add guild_ids=[] so that commands would load faster for those guilds
thanks
how can i get the editted message context from old message id
like the message content was editted and i have its id
hmm
check the docs about interactions i think it's edit original message
I have py-cord installed for some time and started to do some slash commands and suddenly it doesn't recognize cmds.slash_command and discord.Option
It did recognize them before and I first uninstalled discord.py and then installed py-cord
PIng me if you respond please
might be stupid question, but do decorators from yesterday permission v2 commit work ? is it fully released by discord ? because this code is still allowed to be used in dms
not bot owner can use /test too, waited hour as well
so idk, havent seen anybody talk about anything so i feel weird.
from discord import Intents, guild_only, Bot
bot = Bot(command_prefix='~', intents=Intents.all())
@bot.slash_command()
@guild_only()
async def test(ctx):
await ctx.respond('You are in guild.')
bot.run(getenv("DISCORD_YEN_TOKEN"))
Autocomplete interactions can be used for modal textinputs? Or they are only supported by slash command options?
class PickChannel(discord.ui.View):
def __init__(self, chns):
self.channels = chns
@discord.ui.select( # the decorator that lets you specify the properties of the select menu
placeholder = "Chooses a Channel", # the placeholder text that will be displayed if nothing is selected
min_values = 1, # the minimum number of values that must be selected by the users
max_values = 1, # the maxmimum number of values that can be selected by the users
options = channels
)
async def select_callback(self, select, interaction):
#do stuff
await interaction.response.send_message(f"Channel set to {select.values[0]}")
class testing(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def pickchannel(self, ctx):
chns = []
for i in ctx.guild.channels:
chns.append(discord.SelectOption(
label=f"{i.name}",
))
await ctx.send(view=PickChannel(chns))
``` how could I make this work? I'm trying to make a channel selector with select menus
options can only be a list of str or SelectOption and limited to 25 elements iirc
there are 5 channels
class PickChannel(discord.ui.View):
def __init__(self, chns):
self.children[0].options = chns
@discord.ui.select( # the decorator that lets you specify the properties of the select menu
placeholder = "Chooses a Channel", # the placeholder text that will be displayed if nothing is selected
min_values = 1, # the minimum number of values that must be selected by the users
max_values = 1 # the maxmimum number of values that can be selected by the users
)
async def select_callback(self, select, interaction):
#do stuff
await interaction.response.send_message(f"Channel set to {select.values[0]}") ```
You need to define options after creating an instance of the view, you can do it in init method of the view just like I did @slender lintel
nice, works, thanks @slender lintel
Is there a way I could see if an interaction response has been deferred? It seems there is InteractionResponse._responded is it intended for use?
well considering its prefixed with _ it'd suggest its not
You can't check if an interaction is deferred, but you can check if an interaction is responded - InteractionResponse.is_done()
Oh well, that still means deferred wouldn't it
Since deferred interactions are considered responded
Exactly
Follow up question, how do i send modals after deferred?
If an initial response has been sent in form of a message then it's considered as responded but not deferred
You can't, modals can only be sent as initial response, so after deferred you can't send them sadly
But yeah you can send modals as an initial response, if it's not been responded yet, InteractionResponse.send_modal(...)
is it currently possible to get the member's guild banner, or not yet?
possible
Is there a fix now to the command registration issue that only a single command appears?
I'm trying to my bot to get a list of the roles assigned to itself, but it keeps returning
"'Bot' object has no attribute 'roles'"
hi, guild.channels returns empty list, why is that? I've set intents.guilds = True
How do I get the message my bot has just sent? I tried client.deposit_msg = await ctx.interaction.response.send_message(embed=text,view=DepositButton())
But I get returned an interaction instead, and trying to access client.deposit_msg.message gives me NoneType
is the guide for slash commands up to date (https://guide.pycord.dev/interactions/application-commands/slash-commands )? I followed it exactly and I get AttributeError: module 'discord' has no attribute 'Bot'
you need pycord > 2.0, pip install py-cord==2.0.0b7
so it's out of date is what I'm hearing
You probably have an older version
Maybe you did pip install py-cord, which installs the older stable version
probably yea since it was listed here: https://guide.pycord.dev/installation
yup on 1.7.3
is there a way to have a select menu within a modal?
what is this? and how it implement in bot?
Nope
Update to master
Pretty dumb question but does anyone have examples with using guild.create_text_channel in a view subclass? I kind of looked everywhere
Hey, how i can the embed command edit with buttons also the command has a embed with text so when i click to the button has be change the embed
Traceback (most recent call last):
File "C:\Users\small\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 382, in _run_event
await coro(*args, **kwargs)
TypeError: on_message() missing 1 required positional argument: 'message'```
async def on_message(ctx, message):
contents = message.content
for bad_word in bad_words:
if bad_word in contents:
await message.delete()
await ctx.send(f"{message.author.mention} your message has been censored.")```
any fix?
no ctx
message.channel.send
Is it not possible to use a commands.Paginator with a bridge.BridgeContext?
I get expected Context not <class 'discord.ext.bridge.context.BridgeApplicationContext'>
I thought bots didn't need messages intent enabled to delete their on sent messages? Or am I missing something?
it is a ephemeral message
#971846901152497694 message I see
You can't delete ephemeral messages
remove the return and try it again
not with commands.Paginator (i didn't even know this existed), but ext.pages supports bridgecontext
Oh, whoops, it's ext.pages.Paginator that's throwing the error. b7
uhhh what exactly is throwing the error?
(I have to use commands.Paginator in the same function, but it works fine because it doesn't need a context)
looking at the code paginator.respond allows bridgecontext
embed_paginator = pages.Paginator(pages=embeds, show_disabled=False)
await embed_paginator.send(ctx)
ctx is a bridge context
Testing more, it works with the message command but not with the slash command
should be .respond in a bridge command, but it looks like this actually isn't on b7; it is present in master
anyone else getting a 405 code when syncing commands?
basically b7 ext.pages doesn't properly support bridge commands
can safely ignore it, but permissions v2 is fully functional if you update to the latest master branch
yeah I know but now none of my commands are getting recognised as debug commands so I have to wait like an hour for them to process
though note this completely changes the @permissions decorator if you're currently using it, so make sure to look into that before updating
i'd just update to master then, the perms v2 rollout had some bugs with syncing alongside the 405 which they claimed to have fixed yesterday
yea maybe
Okay, thanks
updated to master
and ui doesn't exist
OMEGALUL
ui definitely exists in master
no clue what you're doing wrong there
maybe just download it manually from github and throw in the files yourself
i mean you could do load_cogs? and sync and register commands? did not know that
is it pushed to pypi?
o
you probably installed 1.7.3
all good
if you want master you should install git+https://github.com/Pycord-Development/pycord
if using pip
yea ty
yep this is what i use
๐
also remember if you're updating to master, things like @permissions.has_role, is_user etc were removed because discord implemented a new permission system... for better or worse. If you're using them, you should switch to ext.commands.has_role etc which are internal checks
OO IT WORKED
nice
any idea where i could see how perm v2 looks like? better if in python
well
load_cogs is a function in my bot class, the rest is just inheritance
ohhh i see hahaha
it's literally just @permissions.default_permissions and @permissions.guild_only https://github.com/Pycord-Development/pycord/blob/master/discord/commands/permissions.py
which sucks because now you can't set user/roles via the bot on discord's end, you have to use internal checks
which is fine if you can access the integrations panel in your servers but otherwise a pain
(and if you don't own the server, you can't add your own permission to it)
ohhh then would the ext.commands.permissions still work after and disable the commands if one does not have any permission?
ext.commands checks are all internal, so they will continue to work
but they won't hide commands
but they would disable it right?
you want owner only commands to be hidden? haha nope
ext commands would still grey out commands right?
owsheeee
that's bad hahaha
ohhh right there'a a way but the commands won't be hidden
the commands would only respond 'you don't have permission to use that command' if you have no permission
pretty much
the best solution for owner commands now is to register them to a single guild you control but that just makes them so much more inconvenient to use
for me i am trying to group all admin commands in to the admin group
if it's relying on discord permissions like administrator=True then permissions v2 should work for you
it is easier to manage in integration but restricting
yeah
only need to change one thing to enable it on all sub commands but has a lot of downs too
a dashboard would be better for further customization
Oop, was just about to ask about hiding commands, hahaha, glad I checked here when I did.
yep server setting > integrations > bot
Nice. Thank you.
On a second note though, what'd be the most elegant solution if I want to use both slash commands AND standard prefix commands? Or is that really more painful than it sounds...
do you mean the same command as slash and prefix?
bridge
or just using them alongside
Same command
but bridge does not have group commands iirc
Fantastic! Just needed a point in the right direction haha
a bit basic at the moment but it does do the job for the most part
Yeah, I don't have command groups so that works.
also you ctx.send() would throw a interaction failed on / and ctx.respond on prefix
well in bridge you're meant to use respond anyway
Yeah, I branched my main repo and have a functioning slash commands rewrite, but want to conduct a poll on my community if they want me to keep the original prefix as well, or just go all in on slash commands.
I'd prefer to go all in on slash commands, but I'm not sure if there'd be serious backlash.
if newer slash command features make it easier to develop over prefix i'd just go all in
currently bridge is the best solution for your situation but it has its cons too
stuff like autocomplete and smarter options made features i wanted to implement actually possible on a scale
Yeah, slash commands have been wonderful thus far.
ohh right about slash commands
they are less prone to user errors
if you configure it right
yeah it's easier to guide them
so I'm trying to make the bot send a list of users but instead of it sending just like user IDs I want it to send the names like Rad#3196 Without pinging them. I'm using json files btw
you could also add descriptions on commands and parameters
There's one case that sorta irks me with slash commands. I had a feature that allows you to search a role to tag and it could convert those annoying ๐ช๐ฃ๐๐๐ค๐๐ ๐๐ค๐ฃ๐ฉ๐จ back into plaintext in the backend. Doesn't seem to be a way to have an option be either a role or str()
what is leaders a list of?
users
fetch_member(id) if i am correct
use get_or_fetch_user https://docs.pycord.dev/en/master/api.html#discord.Client.get_or_fetch_user
alright
if you input discord.Role, you should be able to use the role ID
similar to discord.Channel, discord.Member etc.
but (whacky) unicode fonts in general are just a pain
Yeah, it's just difficult for most users to get a role's ID.
might be weird but maybe you could use an autocomplete?
have some custom logic to convert their names
hell you say you already have the plaintext logic, you should be able to use that to some extent
Python actually has a built in function for the conversion part, just unfamiliar with how to create options so perhaps an autocomplete would do the trick.
or make a command that returns the user's or role's id?
yeah i'd look into autocomplete
it's very useful for searching when the user doesn't know the exact input
I just want to retain the functionality of what you get when you're using a Option(discord.Role, **)
Thanks for the tip, I'll have a look into that.
strictly speaking, if the autocomplete only returns role names in guild.roles you should be able to convert it safely back to a role with discord.utils.get
Oh yeah, all that conversion stuff between weird role names and back to a role object is something I built a fun little nightmare library to do automagically, it's more just populating the autocomplete options.
isee
well give it a look, you can refer to https://github.com/Pycord-Development/pycord/blob/master/examples/app_commands/slash_autocomplete.py for a basic example
Aha perfection, was just about to look for an example. Thank you so much for the link.
all good
any docs on how to send dm?
if you have a user or member object, it's just user.send
e.g. ctx.author.send would be to whoever ran the command
how about if the allow dm is disabled?
well the only way to check if someone has dms disabled is to try and dm them
okay thanks a lot
if it raises Forbidden they have them disabled i believe
so i think you could handle it with try / except discord.Forbidden
thanks
all good
right aside form auto complete OptionChoice would work too
Got the autocomplete working! Very cool.
Any way to set the color of the autocomplete options though?
EDIT: Looking through the REST API it seems that roles are a distinct option type, while a custom autocomplete seems to only function with string types, so perhaps not.
i can get anything here ๐
my commands are not are not registering parameters
command(ctx, paramhere)
but after running the bot it is not accepting params like this
/command
should be /command paramhere[]
it is inside a cog and a sub command
the insteraction : Interaction seems to be the problem
How do i get information about a user (eg name, display avatar) via the id?
@haughty narwhalcheck this
you need to fetch/get the user first then .name .id after
unfortunately no, autocomplete is purely string
technically discord.Role itself is a built in autocomplete, but obviously it doesn't function for your purpose of detecting unicode names
option choice might be better?
well all slash arguments are technically option choices to some extent
hmmm
but if the autocomplete -> conversion works then hey that's fine
sheee my command params are not showing
ohhh
@test.command()
async def has_role_members(ctx, message:str='Hello'):
for member in ctx.guild.members:
for role in member.roles:
if role.name == 'test':
await member.send(message)
else: pass
message[] is not showing up
I want to make it so like in 3 days time an action happens how do I do that? And like would me turning the bot off mess with it?
basically I do a command it adds something to a list and I want the bot to delete that item after exactly 3 days
Is it possible to create a reaction listener within a function? I want to run a command that spits out an embed and then allows people to react to that embed in order to join a queue for an event. this is what i have right now, im not sure where the listener goes and if it is outside the function how to access its data when it gets triggered
seems to be discord developer's rate limiting
use wait_for("reaction_add") https://docs.pycord.dev/en/master/api.html#discord.Bot.wait_for
though if you're looking for multiple (unknown amount) reactions, you're better off just sleeping
do note you have to fetch the message again to get the reactions
You can use Tasks to complete this. But you would need external storage to keep track of the time if your bot was to go down. And you likely do not want 100 tasks running. So you would want to chunk it. How I do it is I store all my times in a database and every 30 minutes it finds all the timers that would end in the next 30 minutes. Than every minute after that I check if any of the times collected from the 30 minute or less list have ended and than I do the function.
Long term timers are kind of complicated.
basically what I want to do is first I use a command to add a member in a list then that user is supposed to get deleted from that list after 3 days
so what I think I can do is first when I add the user I make another list with the times of when the users were added
When do you access the list?
What triggers you to access the list?
it's easier to store the delete time, then you can just check if delete_time < now
yea that's what I'm trying to do now
wait
this is when I access the list
pretty sure something is wrong cause I'm really new to coding
yea it says discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'list' object has no attribute 'time'
you need to use datetime if it's multiple days
So you access the list from a command?
really you should just always use datetime imo
yea basically when I do d.viewclan it shows me everything I've stored
Thank you!
time is a list and you're calling .time on it instead of calling it on the time module
oh
I see
I'm thinking I can just check all the items in the list and remove all the ones that's under the current time
This is close to what I would do.
I would either make a user class with the attributes of name and remove_time
Or simpler a 2D list like this
[["Rad", endtime], ["Ice Wolfy", endtime]]
And than when you call viewclan you look at the list and remove every item that is past time
yea ok ty
I'd do that too but the thing is
I do this to make the names I've stored be shown as in Rad or smth instead of the ID
and I'd have to change that to remove the , endtime
but now I just have to check all the items in the list and see which ones are below the current time and remove them and the corresponding index of the other list too cause they have the same index
how do i get the list of application commands like client.commands but for application commands?
also abt this so like it wont work if I use time()? I thought I'd use time so I can get it in integers
I dont exactly understand but something like this would work
for pos in range(len(clanMembers)):
if member[pos][1] < now:
member.pop(pos)
what's pos?
Time only works for 24 hours. So it does not know the difference between 1:37 pm today or 1:37om tomorrow. Datetime us the same thing but has a date too.
range len ๐
?
Huh I see
so I'll just change them all to datetime
pos is an int that increases by one every iteration of the for loop
I see
use enumerate
for index, element in enumerate(clanMembers.copy()):
if element[1] < now:
member.pop(index)
Im not very familiar with enumerate would this also avoid the deleting list elements with iterating problem where it skips to element 2 after deleting element 0?
make a copy of the list using .copy() method
idk what the code is doing. Is it cooldown timer?
nope
so like I add a user to a list
what is the goal then?
and its supposed to be deleted after 3 days
now is datetime object
nvm i figured it out, im just dumb lol
and there's a command to access the list
so user triggers that command?
so whenever we access the list I want it to delete any users that's past the date
well yea
is it also triggered via timer?
no there is no timer as the bot will turn off and stuff, I'm gonna make it so if the time mentioned in the list is lower than the current time the item gets deleted from the list
it then copies the index of where the time was lower and then deletes the item of the same index from a different list where the usernames are stored
why not use dictionary like {"Rad": endtime, "Ice Wolfy": endtime}
yea the reason why I'm not doing that
you don't even need to iterate
later on I have to do smth like this
to make the user ids 549587402054696960 like this to just Rad
and if I had them like that {"Rad": endtime,} I don't really know how to alter them in that way
explain the significance of this piece of code to me. Why is it needed?
ok wait
I have them stored like this
the IDs
But I wanna show them like this
this is what this does
so if rad makes a purchase. you want to add it to his list?
no no
Another clan purchases a user
and its added to the list
so yea basically that but instead of a user making a purchase of an item its a clan making a purchase of a user
I haven't played the game you are talking about so I am not very knowledgeable about it
Though I think that the data can be organized better than just list of lists.
hm
like dataclass for example
ig
@dataclass
class ClanMember:
id: str
purchases: list
name: str
ig?
ig = I guess
ah. thanks
just one last thing
over here
what is the element
value
which value?
basically you won't need to do clanMember[index]
it is the value stored at that index
oh ok
Integers? Like epoch?
time doesn't have a date component so how would you know if it's 1 day or 3 days or 5 days?
Hello, I have a question, why is the server region not displayed? It says "deprecated"..
Code: ctx.guild.region
regions are per channel now i believe
as per https://discord.com/developers/docs/resources/guild#guild-object
***** This field is deprecated and is replaced by channel.rtc_region**
maybe docs should be updated to reflect that
also: ctx.guild.channel.rtc_region ?
well not guild.channel, you're looking for a voice channel's rtc_region
okay i try
this error is there:
Ignoring exception in view <testbutton timeout=180.0 children=1> for item <Button style=<ButtonStyle.primary: 1> url=None disabled=False label='General' emoji=<PartialEmoji animated=False name='๐จ' id=None> row=None>:
Traceback (most recent call last):
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\ui\view.py", line 371, in _scheduled_task
await item.callback(interaction)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\extensions\Buttons.py", line 31, in first_button
value=f"**`{interaction.guild.channel_region}`**", inline=True)
AttributeError: 'Guild' object has no attribute 'channel_region'
no....
you need a voice channel object
to get its rtc_region
because guilds literally no longer use region, it's per channel
and if rtc_region is None then it's set to automatic
you're looking for https://docs.pycord.dev/en/master/api.html#discord.VoiceChannel.rtc_region
How could I get a bot to get a list of the roles that it has?
guild.me.roles i guess
One message removed from a suspended account.
Hey what's a good ping range for your bot to stay in? Currently my bot is bouncing in about the 88-102ms range. How much ping should i start worrying about?
anything below is 160-180 is fine, i usually have between 80 and 120
you can check for a change in member flags but for checking how many boosts you probably want to keep track of how many boosts a server has
so you can compare before and after
what exactly do you mean by sleeping
how do i use slash perms in cogs?
discord.ui.Button
from discord.ui import Button
any one of these
can you show pip list
you have 1.7.3 installed
oh....
just await asyncio.sleep(time) then fetch the message to get all the reactions made within that time
that's a better approach if you're looking for an unknown amount of reactions, but if you want to wait for let's say 10 reactions, then using wait_for with a check on the amount of reactions is better
H
Hey how i can level of boosts? not count, level
guild.premium_tier (0 to 3)
thank you
can i make it so my bot replys to pings
but dosent react to reply pings
for example @my_bots_name: works
but if i reply like this i dont want it to work
I wrote the code as below, but the checks are not working.
What can I do?
Sorry, I just installed the 2.0.0b7 version posted on pypi and it works.
how do i make a slash command cooldown
i hv installed py-cord 2.0.0b7 but it still shows 2.0.0b5 in print(discord.__version__)
One message removed from a suspended account.
check for differences in boost amounts 
hey
i know i have to enable the message_content intent on the dev panel if i want to use it
unfortunately my bot is in more then 100 servers and i cant apply yet
so is there any way to force it to turn on?
nop
why can't you apply? you should have been able to at 75 servers
i rly dont have a good reason to apply
well then you kinda have to give up on message content
... its literally just forced by pycord rn
? what intents do you have
you can just set message_content=False
it's not forced by default either, it's only enabled if you explicitly enabled it
ERROR: Command raised an exception: AttributeError: 'int' object has no attribute 'slowmode_delay'
How can I check if the channel has slowmode_enabled?
Oops, I accidentally wrote the slowmode check above get channel variable ๐
Thanks
Hi im trying to edit a message based on its ID heres the code-
sent_message = await ctx.send(content="Message 1")
msgID = sent_message.id
await msgID.edit(content="Message 2")
apparently the code neither edits the message nor gives me any error
help
oh
doesnt but lemme try that
nope still doesnt work
doesnt give any error either :I
...you sure it's running at all?
it only sends the message but doesnt edits it
what if you send another message after trying to edit it
if you're not getting any errors then you screwed up your error handler somehow
hmm
im making a command in such a way that it first sends a message and then edits the message when ANOTHER user initiates the command
idk if u understand
;/
i think i know what you mean but that doesn't seem like the best implementation
yeah :(
One message removed from a suspended account.
not even the ID, you can just store the entire message
Or just the object yeah
just check if the boost count lowered then
Okay cool that makes sense, thank you!
One message removed from a suspended account.
well
you have two options:
- track guild.premium_subscribers and see who's missing
- track
on_member_updateand see who loses their boosting status
note this wouldn't detect a specific user that's doing multiple boosts going down to less boosts, e.g. 2 -> 1
Im currently using the latest version of pycord (2.0.0b7)
And the prefix isnt working. is this a known bug?
message content intent
is set
if you want prefixed commands, you would need message content intent set both in the code and in the dev portal
it is
?tag intents
import discord
from discord.ext import commands
# Get specific intents for fine control
intents = discord.Intents()
intents.emojis = True
intents.guilds = True
intents.messages = True # Required for prefix commands!
...
# Get all non-priveliged intents; this excludes presences, members and message_content
intents = discord.Intents.default()
# Set priveliged intents: these must be enabled on dev portal
intents.members = True
intents.presences = True
intents.message_content = True # Required for prefix commands >= 2.0.0b5
# Get all intents; all intents must be enabled on dev portal.
intents = discord.Intents.all()
# Apply intents when creating your bot
bot = commands.bot(prefix="?", intents=intents)
show bot object
np
.
Yeah i know, but i dont need all
How do you edit the message sent by ctx.respond?
doesn't hurt to hv it all lol
I think I'm just being really thick but I genuinely forgot the way to do it
interaction = await ctx.respond("content")
await interaction.message.edit("e")```
try this
i am not sure actually
I'll give that a shot one sec
.message is None
for both ctx.interaction and the ctx.respond-returned interaction
ctx.followup.edit_message requires a message ID
does ctx.edit not work?
i suppose thts for normal commands
and not for slash cmds
no it works for slash
um
https://docs.pycord.dev/en/master/api.html#discord.Interaction.edit_original_message I wonder if this is it
oh
try it
ok I'll try that one sce
this worked
I definitely knew .edit was a function mhm yep
nice
I was running some tests and added my slash_commands bot to a new server. I know it can take up to an hour for commands to register but it has been at least 12 hours and the commands aren't there?
Ah, wait, #972227609431801977 message found this message. From other threads I figured it could have something to do with the new perms-v2 but couldn't find a solid correlation between my issue and that.
Edit: More recent communications in https://discord.com/channels/881207955029110855/972554650727358535 has proven to be useful too. Excited for the next beta!
Hello, i have tryed a uptime command for looking the bot uptime, i want a datetime format ,,hours, min, sec" but my datetime object is not working?
Code:
times = datetime.datetime.utcnow().strftime('%H:%M:%S')
@bot.slash_command()
async def uptime(ctx):
now = datetime.datetime.utcnow().strftime('%H:%M:%S')
uptimes = now - times
await ctx.respond(uptimes)
Error:
Ignoring exception in command uptime:
Traceback (most recent call last):
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\commands\core.py", line 122, in wrapped
ret = await coro(arg)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\commands\core.py", line 829, in _invoke
await self.callback(ctx, **kwargs)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\main.py", line 28, in uptime
uptimes = now - times
TypeError: unsupported operand type(s) for -: 'str' and 'str'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\bot.py", line 1098, in invoke_application_command
await ctx.command.invoke(ctx)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\commands\core.py", line 331, in invoke
await injected(ctx)
File "C:\Users\zReaxrYT\PycharmProjects\Discord\venv\lib\site-packages\discord\commands\core.py", line 128, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: unsupported operand type(s) for -: 'str' and 'str'
remove the .strftime to get the datetime objects. when you subtract datetime objects from each other it will produce a timedelta with the difference and i believe you can call strftime on that
i have this block of code, i am unsure how to access the user data on the result2 line
in timedelta is seconds, hours.. working yeah but hours, min.. is in seconds..
the math is easy
math has never been my forte.. xd
we know that 1 minute is 60 seconds
yeah i know
60*60*24
Hello, is there a way to have multiple users execute a command using permissions?
@permissions.is_user(198067816245624833) # should accept a list of pre-determined people
these types of permissions aren't supported anymore
Do you by any chance know how these should be handled?
you can use check decorators from ext.commands
When writing a bot in OOP Python, do I need to use command decorators in my Bot class?
you shouldn't really be defining commands inside your bot class
So bot class only for setting it up?
Oh. I see, I was using this file as a guide: https://github.com/Pycord-Development/pycord/blob/master/examples/app_commands/slash_perms.py
It works for one user, but I don't see how to add more users
Pycord, a maintained fork of discord.py, is a python wrapper for the Discord API - pycord/slash_perms.py at master ยท Pycord-Development/pycord
copied one of the examples from the git so far
outside of the bot you can use @bot.command as a decorator to create a command
okay
and event handling like on_message or on_reaction add? That all happens inside of my bot class?
this example is outdated
it's no longer supported
really dread it, but yeah might have to start using cogs
ok, thanks for the help!
@bot.slash_command(name="apply", guild_ids=[])
async def apply(ctx, member):
global idrow
idrow_off = idrow + 1
modal = profile()
await ctx.interaction.response.send_modal(modal)
userid = str(ctx.author.id)
worksheet = sh.worksheet("Roster")
worksheet.update_cell(idrow_off, 6, userid)
role = discord.utils.get(member.guild.roles, name="Junior Operator")
await member.add_roles(role)
role = discord.utils.get(member.guild.roles, name="Junior Operator")
AttributeError: 'NoneType' object has no attribute 'guild'
how do i fix?
please @ me
member is parsed as a string in that state; instead, you should define the member argument as member: discord.Member
in the async def?
@discord.default_permissions() and SlashComandGroup(default_member_permissions=...) isn't working?
config_group = discord.SlashCommandGroup(
"settings", "Manage server settings.", default_member_permissions=discord.Permissions(manage_guild=True)
)
This is still @.everyone -> yes
@commands.slash_command(name="setup")
@discord.default_permissions(manage_guild=True, manage_channels=True, manage_roles=True)
async def foo(...):
This is the same result. No change in the UI.
am I doing something wrong?
Hey, i have a question i have a ping command i want 1 - 200er Ping is a "Good" Ping but my command is not working...
pings = round(bot.latency * 1000)
if pings == 1 - 200:
await ctx.respond(f"Good Ping: {pings}")
else:
await ctx.respond(f'Ping {pings}ms')
Feel free to ask if you don't understand my question
Whatโs not working? And 1 - 200 equals -199 ; you probably want just pings <200
i want when the ping 1 - 200 is, is this a good ping and send this message await ctx.respond(f"Good Ping: {pings}"). when +201 is send this await ctx.respond(f'Ping {pings}ms') yk?
is that even possible?
What I am saying is
1 - 200 = -199 so your if pings == 1 - 200 actually becomes if pings == -199 which wonโt happen.
Thus I suggest if pings < 201 ;
so?
pings = round(bot.latency * 1000)
if pings < 201:
await ctx.respond(f"Good Ping: {pings} - 1")
else:
await ctx.respond(f'Ping {pings}ms - 2')
Yeah, try and see
No change in the UI.
do you mean they aren't hiding from users without those permissions, or nothing's appearing in the integrations tab?
I've got it thanks
I havenโt tested the former but the latter is correct
ah i should have been more specific; the commands show up, but the permissions don't change?
Oh yeah the commands appear in the integration tab and when typing / but just with the default โ@ฤveryone can useโ permission set
so the integrations tab is pretty whack honestly
Discord problem?
it's very subtle how it displays permissions
Well yeah it doesnโt show permissions actually does it
It just shows roles and channels
I just realised that
let's say we have permissions that look like this
if it says default, then that's equivalent to the existing bot setting without changing anything
so for this command the bot has defined that @ everyone is false, but Server Moderator has a permission that is valid
if i was to set Server Moderator to
, the (default) text would pop up next to it
I see
as you can see, this is incredibly intuitive and not confusing at all
Yeah thatโs a bit
Well
Idk what to expect itโs discord
At least perms v2 is better than v1 ig lmao
Let me rephrase
Better -> more customisable
ever so slightly by having default perms yeah
just a pain that bots lose control over user/role
Did many people actually use that for public bots?
for public bots? probably not, it's impractical at that scale
I donโt think thereโs a large enough volume of bots thatโre exclusively used in certain servers for discord to care about it
Theyโd just tell you to check yourself in the code
yeah that's probably the approach
But I can see how per-user would be nice anyway (E.g whitelist)
@commands.Cog.listener()
async def on_application_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
embed = discord.Embed(description="`/slash` command on cooldown!",color=p84clr)
await ctx.respond(embed=embed)
else:
raise error # raise other errors so they aren't ignored```
How come this doesn't work?
Traceback:
TypeError: on_application_command_error() takes 2 positional arguments but 3 were given```
is that in a class?
It's in the cog yes.
you want self, ctx, error
currently having an issue with this, running this code and getting this error output. It fails on return reaction.msg == msg
your checking does not make sense to me
ohhh wait you are printing the line where the code is being executed
you first called the print(53)
since the def check is a function, it won't be executed unless you call it
in try print(58) was executed
after print(58) you called def check in react = await so it executed the function and called print(55)
hence, 53 58 55
thanks!
im now here, for some reason the if react.emoji == ๐: is failing to read the reaction as that emoji. Not sure if im grabbing the emoji from the reaction improperly or what other thing im doing wrong. Console prints made it to line 60 and nothing else with this code
sorry i am not an expert on the emoji/reaction count part i haven't learned that one yet ๐
np
Hi, how can i show a confirmation view on a dropdown callback?
what i want is after selecting smtng on the dropdown it will ask you a yes or no button.
thank you in advance
@tidal beacon
return reaction.message == msg
You've used equal to operator thus it is either returning true or false.
oh nvm it's a check func
edit the message to contain the confirmation view. dont forget to store the result from the dropdown somewhere that is accessible afterwards
already figured it out. thanks!
how can i disable the dropdown after select
select.disabled = True and edit the message to use the updated view
How can I use await to call a asynchronous function in an init ?
Ex:
@class():
def __init__():
await myAsyncFunc()
async def myAsyncFunc():
do..
I'm unable to call the function in the init because it's async.
I tried making the init an async but that just creates a monster of errors.
you cant
But I need to be able to
well
theres no way to call an async function using await
i thought coding was infinite ๐ญ
complain to the python core devs then
you could return an embed with buttons
as callback
i legit need to be able to tho
as i tell you, theres no way to call an async function using await
=docs asyncio.run
what are you trying to do?
asyncio.run if you havent create an event loop
Use await in an init
yep not my field hahaha asyncio errors are everywhere
i don't even know how to catch a future error
or something of the likes if it is correct
does
async def init
works? or does it throw errors?
idk
though i haven't encountered an async class to my knowledge or maybe i did but dis not recognize it? hahaha
you can't async inits in python
errors
see? hahaha async hell
this is something I looked into a while ago when programming an api interface. it's not possible to async your inits
you can use an async factory pattern to initialize your class that way
but the question is why are you trying to async init?
you know how hard that is ;O;
i mean you could try to do it on a function
I'm creating my AI bot to be able to self create values and make it's own classes and functions.
hmmmm i know nothing about ai
Heres a question. does the initialization of the class need to be asynchronous? or can it be a blocking call?
if not it could be a threading?
has to be asynchronous
your best bet is probably the factory pattern
right, do commands work on threads by default or do we need to permit them?
haven't tried it yet but they should work by default right?
I'm seriously getting confused about how the slash command permissions work. Is it not possible to just supply a permission type? like manage_bots permission? or administrator permissions? I don't want to enforce either adding your guilds "admin" permission to the list of admins, nor do I want to enforce needing to create specific named roles to accommodate my bot
nvm ty
๐
I have just found out about the integrations tab. good stuff.
You can also do it in code, documentation soon
is there a simple way of having commands disabled to the everyone role by default? I'm realizing now it's not a huge deal with the bot I'm making but it would be cool to know for the future
Oooooooooooooh
neat!
At first it looked just like the v2 example but that's some good stuff right there
Does anybody else get a 405 Error: Method not allowed when starting their bot?
due to v1->v2 permissions see ##1335 and ##1328
https://github.com/Pycord-Development/pycord/pull/1328
https://github.com/Pycord-Development/pycord/pull/1335
Summary
This is a copy of #1183 to re-do the merge conflict resolution after it was previously broken
Checklist
If code changes were made then they have been tested.
I have updated the documen...
thank you. Hope it will help
wait. Is it on my site or do I only have to wait until it gets fixed?
you can ignore the error, but if you want it gone you can update to the master branch
or wait for the next release
!install
Install pycord:
pip install py-cord```
Install pycord beta:
```pip uninstall discord.py
pip install py-cord==2.0.0b5```
Install pycord alpha from git:
```pip uninstall discord.py
pip install git+https://github.com/Pycord-Development/pycord```
@tall fossil see the last one
also that command needs to be updated
since the latest installable beta is b7 obv
also the latest git is labeled as b7 still which is a bit misleading
what do I have to update?
Where can I get stuff like tutorials
also is it possible to store per server settings in json/sqlite/any other storage with pycord?
The Official Guide for Pycord
and you can use any storage method you can use in python
it's generally preferred to use asynchronous libraries if you're working with databases
ok
e.g. aiosqlite is a popular choice
any examples
What's the code for inputing to the bot like args
Hi
I wanna make
my bot sends a message in slowmode enabled channel in a loop
but the next time it's sending the message it should tell me that there is slowmode of x minutes is enabled
any help would be appreciated
posting the code is better than not
@client.event
async def msg_task():
while True:
#Put comma separated channel ids below in the "channels" list
channels = [970671777187512344, 970671805192876096, 970671832556527639, 970671857458102285, 970671883139817535]
for channel in channels:
chnl = client.get_channel(channel)
if chnl.slowmode_delay > 0: #if the channel in the list has slowmode enabled, but will log the following message in the console
def check(m):
return m.author.id == 970668440639668265
try:
msg1 = await client.wait_for("message", check=check, timeout=5)
if msg1.content == messagee.content:
await chnl.send(messagee)
print(f"Sent message to {chnl} on {chnl.guild.name}") #message sent confirmation message
except asyncio.TimeoutError:
print(f"Slowmode is enabled in {chnl} at {chnl.guild.name}")
else:
try:
await chnl.send(messagee)
print(f"Sent message to {chnl} on {chnl.guild.name}") #message sent confirmation message
await asyncio.sleep(time)
except (discord.Forbidden):
print(f"Can't send message to {chnl}") #message sent failure message
My current code
p.tag install
A tag with this name doesn't exist.
...
e
how to edit a message on button interaction i tried this:
btn1 = Button(
label = 'Survivor Stats',
style= discord.ButtonStyle.success,
)
view = View()
view.add_item(btn1)
interaction = await ctx.respond(embed=embed, view = view)
async def btn1callback(interaction : discord.Interaction):
await interaction.edit_original_message('e')
btn1.callback = btn1callback
did i send same message twice
sorry if i did
await interaction.response.edit_message()
is rest correct?
why are you storing interaction in button? there is no use for it
hm?
why do you have an interaction kwarg in the button constructor?
the command work like it send general stats but if a player want specific survior stats the use button
oh
it copied with wrong indentation
it not inside button
interaction variable assignment
oh
hhow do i edit tho ;-
it give this error await interaction.response.edit_message('e')
TypeError: InteractionResponse.edit_message() takes 1 positional argument but 2 were given
i dont know but thats how you do it
Thank you