#discord-bots

1 messages · Page 956 of 1

midnight gorge
#

db = mongoClient.get_database("database").get_collection("server-data")
db2 = mongoClient['spooky']
antitoggle = db2['antitoggle']
blacklist = db2['blacklist']
gprefix = db['prefix']
limits = db2['limits']

How does this work?

abstract kindle
#

kind of like that random fact module

round robin
#

it gets blacklist value from the db2 database

midnight gorge
round robin
#

mongodb is json

full remnant
#

anyone here

round robin
#

nope

midnight gorge
#

wait let me take a ss on it

unkempt canyonBOT
#

Hey @full remnant!

You either uploaded a .txt file or entered a message that was too long. Please use our paste bin instead.

round robin
#

its still only catching the snipe one

full remnant
#

it's not working

supple thorn
#

!paste

unkempt canyonBOT
#

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 floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

supple thorn
#

you didn't save

round robin
# round robin its still only catching the snipe one
    @commands.Cog.listener('on_message_delete')
    async def log_delete(self, message):
        print("cought logging")```
```py
    @commands.Cog.listener('on_message_delete')
    async def snipe_delete(self, message):
        print("cought snipe")```this is the part that *should* catch it
#

still only catches snipe

full remnant
round robin
#

same thing

round robin
supple thorn
round robin
#

do u know why its not working tho

supple thorn
#

try removing the snipe one

#

check if the log one works now

hardy wing
#

not the link the thing around the entire message

round robin
supple thorn
#

snipe shouldn't be overriding it anymore

hardy wing
#

oh

#

well how would you use one

supple thorn
unkempt canyonBOT
#

class discord.Embed(*, colour=None, color=None, title=None, type='rich', url=None, description=None, timestamp=None)```
Represents a Discord embed.

len(x) Returns the total size of the embed. Useful for checking if it’s within the 6000 character limit.

bool(b) Returns whether the embed has any data set.

New in version 2.0.

For ease of use, all parameters that expect a [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") are implicitly casted to [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") for you.

Changed in version 2.0: `Embed.Empty` has been removed in favour of `None`.
hardy wing
#

thnx

round robin
#

not catching it

#

even with the other removed

hushed galleon
round robin
#

no clue why it wouldnt work then

hardy wing
#

so when using it would it be like

await message.channel.embed('this is a message',red,title,rich) ```
supple thorn
round robin
#

yes

supple thorn
#

did you load that cog in

hushed galleon
round robin
#

yes

#

its loaded because the commands in it work

supple thorn
#

did you reload it when you added the log one

round robin
#

i restarted the bot so yes

hardy wing
#

is there an example somewhere I can see of this

hushed galleon
#
embed = discord.Embed(
    title='hello world',
    description='funny'
).set_author(
    name='you'
)
# embed.description = '...' also works
await channel.send(embed=embed)```
hardy wing
#

oooooh alright now I get it

round robin
#

theres also set_footer
and embed.timestamp

supple thorn
supple thorn
#

you can share the code of the cog the log listener is in

#

maybe something there is fucking up your listener

round robin
#

the command i just put in it doesnt work

#

something is broke with cog setup

#

class MessageLog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener('on_message_delete')
    async def log_delete(self, message):
        print("cought logging")
        mydb.reconnect()
        mycursor.execute("select `message_log` from serversettings WHERE server_id = %s", (message.guild.id, ))
        mydb.close()
        print(f"2, LOG: {message_log}")
        for (message_log) in mycursor:
            message_log = int(message_log)
            if message_log != 0:
                channel = bot.get_channel(message_log)
                await channel.send("hi")

    @commands.command()
    async def tt(self,ctx):
        await ctx.send("testingS")

def setup(bot):
    bot.add_cog(MessageLog(bot))```
#

i copied that cog over (or should have) from a working one

#

ill try to add it into a diffrent one thats working

#

still doesnt work

#

im so stupid

#

** i didnt load the cog**

midnight gorge
round robin
#

i havent used mongodb

#

i just know thats how getting json values works

midnight gorge
#

ok

round robin
#

nice cought snipe cought logging

#

python is a love hate relationship

supple thorn
#

if you did then your cog is fucked

round robin
#

i forgot to add the part for that category

#

so it never even attempted to load

supple thorn
round robin
#

lol

#

its working now tho

slate swan
#

using await ctx.invoke(self.bot.get_command('roster'), role=role.name) Could i make this empheral? even if the command is a regular command? Im using the command inside of a interaction

torn sail
#

Probably not

azure scroll
#

is it possible to have aliases for a command in a cog

torn sail
#

Yeah

#

Would be same as u normally did

azure scroll
#

u mean aliases="foo"

azure scroll
torn sail
#

@commands.command(aliases=[“foo”])

wicked lily
#

so the next time you type foo

#

it will do the command

azure scroll
azure scroll
#
user = self.client.get_user(ctx.author.id)
await user.send(embed = timeupEmbed)

error:

AttributeError: 'NoneType' object has no attribute 'send'```
supple thorn
#

Also you could just do ctx.author.send

azure scroll
supple thorn
unkempt canyonBOT
#

Using intents in discord.py

Intents are a feature of Discord that tells the gateway exactly which events to send your bot. By default, discord.py has all intents enabled, except for the Members and Presences intents, which are needed for events such as on_member and to get members' statuses.

To enable one of these intents, you need to first go to the Discord developer portal, then to the bot page of your bot's application. Scroll down to the Privileged Gateway Intents section, then enable the intents that you need.

Next, in your bot you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:

from discord import Intents
from discord.ext import commands

intents = Intents.default()
intents.members = True

bot = commands.Bot(command_prefix="!", intents=intents)

For more info about using intents, see the discord.py docs on intents, and for general information about them, see the Discord developer documentation on intents.

azure scroll
zenith hare
#

hello, some time ago I found out that discord.py had been discontinued, and recently I wanted to make a bot again, but now I find that there are several libraries, such as pycord, discord.py 2.0, another one called discord.py rewrite I don't know if it's the same as 2.0, I want to use buttons and slash commands, so, any specific library you recommend? ,'

zenith hare
supple thorn
#

yes

#

or you could just install it the easy way

#

without having to write the github link

supple thorn
#

pretty much ui

zenith hare
#

buttons and slash cmds?

supple thorn
#

i rewrote my code to disnake

zenith hare
#

disnake is better?

supple thorn
#

i personally use it and haven't gotten any problems

supple thorn
#

it has buttons, modals, views etc

zenith hare
slate swan
#

ngl

slate swan
#

when danny discontinued development of discord.py in around august

supple thorn
slate swan
#

there are many forks who are actively working on the project

#

and there is less chance of them discontinuiing

zenith hare
slate swan
#

and danny is still not sure if he's gonna discontinue the project, (no assurance)

#

so i advice u to move to another lib for security

supple thorn
supple thorn
#

but with disnake

slate swan
#

he said that in his server :'/

zenith hare
zenith hare
supple thorn
slate swan
supple thorn
#

he said this in the disnake server

"discord.py announced that it is resuming development as of today, after about a 6-month long hiatus.
While that is certainly a surprise to many, rest assured that disnake is not going to stop development!"

slate swan
#

same with many other forks ^^

#

@zenith hare i advice u to look into docs of the forks & see which one seem more comfortable to u :'/

#

cuz i've tried py-cord so i'm in favor of it.. & i can't judge disnake because i never tried it

zenith hare
#

Well, I don't see a problem with comfort, I just want a library that doesn't die, and that can use all the features that discord gives, without much problem

slate swan
#

and they're even making their guide for beginners

zenith hare
#

anyway thank you very much, I'll be seeing what library I will use ,'

slate swan
#

alright

#

gl!

#

consider checking out hikari if you want a non-forked library.

spring flax
#

What's so proiminent about hikari?

brazen raft
#

It's a statically typed library

#

And they will eventually be providing compiled components optionally over pure Python ones, so things run faster, I guess

supple thorn
#

for a api wrapper to be a wrapper it needs to have wrappers right?

spring flax
brazen raft
brazen raft
#

I've tried it exactly once and I don't remember

#

But I guess so, I don't remember whether it has a command system like discord.py has

#

This is the example they have put on PyPi

import hikari

bot = hikari.GatewayBot(token="...")

@bot.listen()
async def ping(event: hikari.GuildMessageCreateEvent) -> None:
    # If a non-bot user sends a message "hk.ping", respond with "Pong!"
    # We check there is actually content first, if no message content exists,
    # we would get `None' here.
    if event.is_bot or not event.content:
        return

    if event.content.startswith("hk.ping"):
        await event.message.respond("Pong!")

bot.run()
spring flax
#

yeah the examples show its an on_messaeg

#

i wonder how arguments would be like then

brazen raft
brazen raft
#

You'd have to parse commands on your own or use third party libraries

spring flax
#

yeah i never used js but i saw it now ```py
@bot.listen()
async def on_message(event: hikari.GuildMessageCreateEvent) -> None:
"""Listen for messages being created."""
if not event.is_human or not event.content or not event.content.startswith("!"):
# Do not respond to bots, webhooks, or messages without content or without a prefix.
return

args = event.content[1:].split()

if args[0] == "image":
    if len(args) == 1:
        # No more args where provided
        what = ""
    else:
        what = args[1]
brazen raft
#

BUT

#

It has logging built into it

#

And set up

#

By default

spring flax
#

but I'm curious to find out why I heard it was a very library

slate swan
#

!pip hikari-lightbulb

unkempt canyonBOT
slate swan
#

!Pip hikari-tanjun

unkempt canyonBOT
slate swan
#
import lightbulb

bot = lightbulb.BotApp(tokens="", prefix="")

@bot.command
@lightbulb.command("name", "description")
@lightbulb.implement(lightbulb.PrefixCommand, lightbulb.SlashCommand)
async def command(context: lightbulb.Context ) -> None:
  ...

bot.run()``` a basic bot
spring flax
slate swan
# spring flax oh i see, how would a member argument look like?
@bot.command
@lightbulb.option("member", "mention a member", type=hikari.Member)
@lightbulb.command("name", "description")
@lightbulb.implement(lightbulb.PrefixCommand, lightbulb.SlashCommand)
async def command(context: lightbulb.Context ) -> None:
  member = context.options.member
  ...```
spring flax
#

that's a lot of decos lol

slate swan
#

thats for a reason, you are implementing the SlashCommand and PrefixCommand within the same function, so parsing of contents in message commands, and in SlashCommand options wont be same without using these

#

if you're really interested in having arguments inside the function you can just add pass_options=True inside the @lightbulb.command decorator. but that won't save you from using the decorators

placid skiff
#

disnake's much better hahah

slate swan
#

there's no comparison. hikari in general is better than any forks.

feral lichen
#

hey i was wondering why the roles arent being removed in this code? thanks ```py
@bot.command()
@has_any_role('demand1', 'demand2')
async def demand(ctx):
guild = ctx.guild
self = ctx.author

demand1 = discord.utils.get(guild.roles, name="demand1")
demand2 = discord.utils.get(guild.roles, name="demand2")
role_names = ('example1', 'example2')

if demand1 in self.roles and demand2 in self.roles:
    await self.remove_roles(demand2)
    roles = discord.utils.get(ctx.guild.roles, name=role_names) #<--line here with problem
    await member.remove_roles(roles)
    await ctx.send("demanded")
heavy folio
feral lichen
#

just the problem is none of the roles in role_names are taken away

#

i use to have it like ```py
roles = tuple(discord.utils.get(ctx.guild.roles, name=n) for n in role_names)

placid skiff
#

!d discord.utils.get

unkempt canyonBOT
#

discord.utils.get(iterable, /, **attrs)```
A helper that returns the first element in the iterable that meets all the traits passed in `attrs`. This is an alternative for [`find()`](https://discordpy.readthedocs.io/en/master/api.html#discord.utils.find "discord.utils.find").

When multiple attributes are specified, they are checked using logical AND, not logical OR. Meaning they have to meet every attribute passed in and not one of them.

To have a nested attribute search (i.e. search by `x.y`) then pass in `x__y` as the keyword argument.

If nothing is found that matches the attributes passed, then `None` is returned.

Changed in version 2.0: The `iterable` parameter is now positional-only.

Changed in version 2.0: The `iterable` parameter supports [asynchronous iterable](https://docs.python.org/3/glossary.html#term-asynchronous-iterable "(in Python v3.10)")s...
placid skiff
#

as you can see it takes an iterable and a kwargs of attributes, you are giving him two iterators, essentially it returns None

#

when you pass multiple attributes they are checked using logical AND, it means that it will return something only if all the attributes that you've passed in it are resolved

#

read the documentation before using methods that you don't know, utils.get is pretty hard to understand

urban ingot
#

!rank

unkempt canyonBOT
#

Iterating over range(len(...)) is a common approach to accessing each item in an ordered collection.

for i in range(len(my_list)):
    do_something(my_list[i])

The pythonic syntax is much simpler, and is guaranteed to produce elements in the same order:

for item in my_list:
    do_something(item)

Python has other solutions for cases when the index itself might be needed. To get the element at the same index from two or more lists, use zip. To get both the index and the element at that index, use enumerate.

sullen pewter
#

How to enable Intents

placid skiff
#

!intents

unkempt canyonBOT
#

Using intents in discord.py

Intents are a feature of Discord that tells the gateway exactly which events to send your bot. By default, discord.py has all intents enabled, except for the Members and Presences intents, which are needed for events such as on_member and to get members' statuses.

To enable one of these intents, you need to first go to the Discord developer portal, then to the bot page of your bot's application. Scroll down to the Privileged Gateway Intents section, then enable the intents that you need.

Next, in your bot you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:

from discord import Intents
from discord.ext import commands

intents = Intents.default()
intents.members = True

bot = commands.Bot(command_prefix="!", intents=intents)

For more info about using intents, see the discord.py docs on intents, and for general information about them, see the Discord developer documentation on intents.

feral lichen
#
role_names = ('Arizona Cardinals', 'Atlanta Falcons', 'Baltimore Ravens', 'Buffalo Bills', 'Carolina Panthers', 'Chicago Bears', 'Cincinnati Bengals', 'Cleveland Browns', 'Dallas Cowboys', 'Denver Broncos', 'Detroit Lions', 'Green Bay Packers', 'Houston Texans', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Las Vegas Raiders', 'Los Angeles Chargers', 'Los Angeles Rams', 'Miami Dolphins', 'Minnesota Vikings', 'New England Patriots', 'New Orleans Saints', 'New York Giants', 'New York Jets', 'Philadelphia Eagles', 'Pittsburgh Steelers', 'San Francisco 49ers', 'Seattle Seahawks', 'Tampa Bay Buccaneers', 'Tennessee Titans', 'Washington Commanders')
     


    if demand1 in self.roles and demand2 in self.roles:
        # Remove the first one if the author has both roles
        await self.remove_roles(demand2)
        member = ctx.message.author
        roles = tuple(discord.utils.get(ctx.guild.roles, name=n) for n in role_names)
        await member.remove_roles(*roles)
        await ctx.send("demanded")
``` ok so i got it to remove both of the roles, yeah thats cool, but it doesnt send "demanded" after anymore. Anyway to fix this?
feral lichen
lofty pecan
#

Hey there I was wondering if there was a good way to make a bot that would get information from a dictionary when the user type a command. For example, I type /name of someone and the bot returns an embed message with the information and pictures associated with that character

idle sparrow
lofty pecan
#

I'm not sure what to look for

idle sparrow
#

what do u want it to do

#

be a bit more specific

lofty pecan
#

Okay so it would be a bot for artists. They can enter information about their characters and then the users can just type a command to get information about them

#

I thought that dictionary was a good way to store the data so it's normalized

idle sparrow
#

long term project and use?????

lofty pecan
#

My question was how to make the bot access the file containing the dictionary

lofty pecan
idle sparrow
#

hmmmm

slate swan
#

hey sometimes when i dump something to a json file sometimes it dump 2 times

idle sparrow
#

maybe look into sqlite3

slate swan
#

like

{"926129108696580186": 956133659965005864, "926129108696580186": 956133659965005864}
lofty pecan
#

Ho god

#

Is it related to SQL

idle sparrow
slate swan
#

no

idle sparrow
slate swan
#

i really cant find any helpful website

lofty pecan
#

Oh it's SQL for python?! No way!

idle sparrow
lofty pecan
#

I did some SQL at uni

slate swan
#

is that the problem

idle sparrow
idle sparrow
#

is a minimal sql system

lofty pecan
#

Nice!

slate swan
#

wait

lofty pecan
#

Well then I'll try to look into that more later I can't access my pc rn

slate swan
spring flax
#

Use aiosqlite if its for a discord bot

#

!pypi aiosqlite

unkempt canyonBOT
idle sparrow
# lofty pecan Nice!

things can get more complex thou
especially if u design something like economy

slate swan
lofty pecan
#

Nah I won't

#

It's a really straight forward bot

idle sparrow
lofty pecan
#

It's just "give me info about this guy*

#

Well thanks!

idle sparrow
#

okay good luck

lofty pecan
#

See you!

spring flax
#

It's blocking

idle sparrow
#

why

spring flax
#

Whilst aiosqlite is asynchronous

spring flax
unkempt canyonBOT
#

Why do we need asynchronous programming?
Imagine that you're coding a Discord bot and every time somebody uses a command, you need to get some information from a database. But there's a catch: the database servers are acting up today and take a whole 10 seconds to respond. If you do not use asynchronous methods, your whole bot will stop running until it gets a response from the database. How do you fix this? Asynchronous programming.

What is asynchronous programming?
An asynchronous program utilises the async and await keywords. An asynchronous program pauses what it's doing and does something else whilst it waits for some third-party service to complete whatever it's supposed to do. Any code within an async context manager or function marked with the await keyword indicates to Python, that whilst this operation is being completed, it can do something else. For example:

import discord

# Bunch of bot code

async def ping(ctx):
    await ctx.send("Pong!")

What does the term "blocking" mean?
A blocking operation is wherever you do something without awaiting it. This tells Python that this step must be completed before it can do anything else. Common examples of blocking operations, as simple as they may seem, include: outputting text, adding two numbers and appending an item onto a list. Most common Python libraries have an asynchronous version available to use in asynchronous contexts.

async libraries
The standard async library - asyncio
Asynchronous web requests - aiohttp
Talking to PostgreSQL asynchronously - asyncpg
MongoDB interactions asynchronously - motor
Check out this list for even more!

spring flax
idle sparrow
#

eh

spring flax
#

!pypi aiosqlite

unkempt canyonBOT
spring flax
#

There'll be examples

idle sparrow
#

the documentation in them are an atrocity

#

but meh you do you

lofty pecan
#

Ho

hoary cargo
lofty pecan
#

I see that options are multiple

#

To be honest I have no idea how that works at all. All I do is science programming

idle sparrow
#

hehe

crimson scroll
#

Hi. Who can advise?
This code not worked with "Manage Roles" permissions but worked with "Administrator"

async def add_role(ctx, role_name):
        member = ctx.author
        role = discord.utils.get(member.guild.roles, name=role_name)
        await member.add_roles(role)

How can I give roles to users without making bot administrator?

placid skiff
#

the bot needs permission to manage

#

also with manage roles permission he can set roles on user which are lowest in index on roles list from the role that the bot has

crimson scroll
slate swan
#

to make sure whats the problem

placid skiff
crimson scroll
slate swan
#

he said he try to give the lowest role

slate swan
placid skiff
#

show us the role list of your server

slate swan
#

yes

#

but in admin it work prob the role has adminis perms

placid skiff
#

could be

#

honestly i always find discord roles a lot confusing, they could be better

slate swan
#

hmm

#

@crimson scroll check the role perms that ur giving

spring flax
slate swan
#

..

spring flax
crimson scroll
slate swan
spring flax
#

Not sure how but okay

slate swan
#

xD

slate swan
crimson scroll
#

i upped role and all work. Totally non-obvious

#

And admin perrmission ignore roles list

spring flax
slate swan
oak warren
#

okay so i have a message with a button on click which i reply with an ephemeral message with 2 more buttons how to edit the ephemeral message after the second button is press
( disnake )

slate swan
#

my snipping dont have that

crimson scroll
slate swan
#

ohk

placid skiff
slate swan
#

show

oak warren
#

how to i edit the ephemeral message

placid skiff
oak warren
#

i have done that too

placid skiff
#

i need to check the context, different context has different methods

slate swan
#

idk tbh

oak warren
#

no that wont work

placid skiff
#

i have to see the code to help you D_D

oak warren
#

okay 1 sec

placid skiff
#

*please tell me that he uses type-hints

slate swan
oak warren
#
class applyconfirm(disnake.ui.View):
    def __init__(self):
        super().__init__(timeout=None)
        self.add_item(applyselect())
    @disnake.ui.button(label="Confirm",style=disnake.ButtonStyle.green,custom_id="confirm_button")
    async def confirm(self,button:disnake.ui.Button,interaction:disnake.MessageInteraction):
        await interaction.edit_original_message(content="Operation done")
    @discord.ui.button(label="Cancel",style=discord.ButtonStyle.red,custom_id="cancel_button")
    async def cancel(self,button:disnake.ui.Button,interaction:disnake.MessageInteraction):
        await interaction.edit_original_message(content="Operation canceled")
placid skiff
#

don't break my dreams

slate swan
#

alr

oak warren
#

i do

placid skiff
#

he does 😄

oak warren
#

typehints are good

placid skiff
#

ok, one sec

slate swan
#

how do i typehint ctx??

oak warren
#

commands.Context

slate swan
#

alr thanks

placid skiff
slate swan
#

typehinting ctx make code loke cool

slate swan
#

else those white letters

placid skiff
oak warren
#

yes

slate swan
#

this looks cool

oak warren
#

it gives not responded

placid skiff
#

!d disnake.MessageInteraction.original_message

unkempt canyonBOT
#

await original_message()```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Fetches the original interaction response message associated with the interaction.

Here is a table with response types and their associated original message...
placid skiff
#

this methods returns the original interaction sent of the message

#

essentially it returns a message object of the interaction

oak warren
#

i see

#

oh i got it i think

slate swan
#

how can i giove defaault typehint to ctx instead of adding in each command

oak warren
#

i think i should have asked in the disnake server lol

oak warren
slate swan
#

no

#

my lib dont

slate swan
oak warren
#

what lib do you use?

slate swan
#

snake]

oak warren
#

oh disnake

#

it does that

slate swan
#

but my ss

oak warren
#

dpy does it implies all forks do it

#

thats a vscode thing it will work without typehint as well

slate swan
#

im talking about those coloras

placid skiff
slate swan
#

sry im typing with 1 finger

slate swan
#

uh vsc hav an shortcut i forgot

#

u know?

placid skiff
#

btw make the intellisense of your IDE working isn't the purpose of type-hints xD, it is just a side effect
type hints make the code more readable for others, with python you don't need to tell the type of a variable so if you don't use type hints other people can not know that type that variable is

slate swan
#

i need colors!

#

xD

slate swan
slate swan
#

also it give recommendation

placid skiff
#

as i said it is just a side effect xD

#

now your ide recognize that your ctx variable is a Context object

slate swan
#

ye

oak warren
# unkempt canyon

ok i got it we both were wrong i am not replying to the interaction i am editing the message so its interaction.response.editmessage

#

ty anyways

placid skiff
#

lol i'm working so i'm not taking to much time to read everything xD

oak warren
#

okay np

maiden fable
#

@placid skiff congrats on the nitro!

slate swan
#

🥲

placid skiff
maiden fable
#

Let's hope you don't over use emojis like a few people, here

placid skiff
#

*Coff coff Ashley

slate swan
#

few*

maiden fable
placid skiff
#

i'm just jokin hahaha

granite parcel
#

how do i edit image color which library i should use?

visual island
granite parcel
#

docs?

visual island
#
junior verge
#

Is there a on_message_sent like:

async def on_message_delete(self, message):
visual island
#

on_message is where the message create event being dispatched.

spring flax
#

!d discord.on_message

unkempt canyonBOT
#

discord.on_message(message)```
Called when a [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") is created and sent.

This requires [`Intents.messages`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.messages "discord.Intents.messages") to be enabled.

Warning

Your bot’s own messages and private messages are sent through this event. This can lead cases of ‘recursion’ depending on how your bot was programmed. If you want the bot to not reply to itself, consider checking the user IDs. Note that [`Bot`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot "discord.ext.commands.Bot") does not have this problem.
junior verge
#

Ah okay thanks

#

What does this mean?

visual island
#

It means that the field 0 (the first field)'s value is required, but you didn't provide it.

junior verge
#

I think I did though, want to see my code?

visual island
#

sure, note that discord doesn't allow you to pass an empty string to the value

junior verge
#
@commands.Cog.listener()
    async def on_message(self, message):
    
            channel = self.client.get_channel(960860760416866335)
            sent = Embed(
                description=f"Message sent in {message.channel.mention}", color=0x4040EC
            ).set_author(name=message.author, url=Embed.Empty, icon_url=message.author.avatar_url)

            sent.add_field(name="Message", value=message.content)
            sent.timestamp = message.created_at
            await channel.send(embed=sent)
hushed galleon
#

kind of weird to log all messages

junior verge
#

It's just to test atm

hushed galleon
#

regardless consider that the message you send is only an embed

#

so the event triggers itself again with a message that has no content

visual island
#

The code looks fine, have you enabled message_content intent? Your bot cant see messages content without that intent.

hushed galleon
#

not to mention there can also be other sources of content-less messages too

junior verge
#

Uhm so what do I do

hushed galleon
#

check if the message content is empty, maybe provide a default and also add a bot user check to prevent infinite recursion

junior verge
#

I'll just remove it

hoary cargo
#

though, the message content can't be empty, otherwise wouldn't be a message

visual island
hoary cargo
visual island
hushed galleon
#

that and their listener isnt only recording user messages, there's no check on who that message comes from

paper sluice
#

oh while subclassing commands.HelpCommand, u get the channel by get_destination, how do u get the context?

hybrid mural
#

Can it be that Discord Bots cannot join Voice Chats while being hosted on servers?

silent ermine
hybrid mural
#

Yeah i know they can join voice channels

#

it works when i host it on my laptop

silent ermine
hybrid mural
#

but it doesnt work when im hosting it on my server

supple thorn
silent ermine
silent ermine
supple thorn
#

I'm asking what server

silent ermine
supple thorn
#

🗿

silent ermine
silent ermine
supple thorn
hybrid mural
#

bought a server from there and am now trying to host it on there

silent ermine
#

but ill look hold on

supple thorn
hybrid mural
#

Nah it supports Game servers but it has more

silent ermine
hybrid mural
#

No errors

supple thorn
silent ermine
hybrid mural
#

ive noticed though that on heroku i.e it had to have opus to join voice chats or something

supple thorn
#

Opus?

#

What the fuck is that

hybrid mural
#

i have no idea aswell

silent ermine
hybrid mural
#

Opus is a codec for interactive speech and audio transmission over the Internet.

#

perhaps this audio transmission over the internet is what i need

silent ermine
hybrid mural
supple thorn
supple thorn
silent ermine
#

And did you configure the server? Like python 3.8 or 3.9

hybrid mural
silent ermine
#

And what python version do you have installed?

hybrid mural
#

same one

supple thorn
silent ermine
silent ermine
#

!paste

unkempt canyonBOT
#

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 floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

vale wing
#

opus/ffmpeg is a codec or smth

hybrid mural
hybrid mural
vale wing
#

Not being able to play music?

hybrid mural
#

yeah

vale wing
#

What OS

hybrid mural
#

Ubuntu

#

the server is on ubuntu 18.04 i think

vale wing
#

Do both sudo apt install ffmpeg and pip3 install ffmpeg and you should have no issues with it

hybrid mural
#

triyng that atm

vale wing
#

sudo apt install python3-pip

hybrid mural
#

im reading it may be an issue with python version 3.10

#

i guess ill install it through git and transfer it to the server

feral lichen
#
role_names = ('Arizona Cardinals', 'Atlanta Falcons', 'Baltimore Ravens', 'Buffalo Bills', 'Carolina Panthers', 'Chicago Bears', 'Cincinnati Bengals', 'Cleveland Browns', 'Dallas Cowboys', 'Denver Broncos', 'Detroit Lions', 'Green Bay Packers', 'Houston Texans', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Las Vegas Raiders', 'Los Angeles Chargers', 'Los Angeles Rams', 'Miami Dolphins', 'Minnesota Vikings', 'New England Patriots', 'New Orleans Saints', 'New York Giants', 'New York Jets', 'Philadelphia Eagles', 'Pittsburgh Steelers', 'San Francisco 49ers', 'Seattle Seahawks', 'Tampa Bay Buccaneers', 'Tennessee Titans', 'Washington Commanders')
     


    if demand1 in self.roles and demand2 in self.roles:
        # Remove the first one if the author has both roles
        await self.remove_roles(demand2)
        member = ctx.message.author
        roles = tuple(discord.utils.get(ctx.guild.roles, name=n) for n in role_names)
        await member.remove_roles(*roles)
        await ctx.send("demanded")
``` this works but why doesnt it send "demanded"
#

it only works with like 3 roles then it sends it

placid skiff
#

why the * in remove_roles?

slate swan
#

and the member is named as self.

feral lichen
#

i didnt bother since it still worked

#

but still, its doing the command besides for sending “demanded” after. Why so?

supple thorn
#

You sent the embed object

placid skiff
supple thorn
#

send has a embed kwarg

#

!d discord.ext.commands.Context.send

unkempt canyonBOT
#
await send(content=None, *, tts=False, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, allowed_mentions=None, reference=None, ...)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Sends a message to the destination with the content given.

The content must be a type that can convert to a string through `str(content)`. If the content is set to `None` (the default), then the `embed` parameter must be provided.

To upload a single file, the `file` parameter should be used with a single [`File`](https://discordpy.readthedocs.io/en/master/api.html#discord.File "discord.File") object. To upload multiple files, the `files` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.10)") of [`File`](https://discordpy.readthedocs.io/en/master/api.html#discord.File "discord.File") objects. **Specifying both parameters will lead to an exception**.

To upload a single embed, the `embed` parameter should be used with a single [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") object. To upload multiple embeds, the `embeds` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.10)") of [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") objects. **Specifying both parameters will lead to an exception**.
supple thorn
#

Use the embed kwarg

#

It's a kwarg specifically for sending a embes

supple thorn
#

Look at this

#

Use the embed kwarg rather than the content kwarg

hollow plover
#

hi

#

where is the help command in RoboDanny's code?

#

i want to see how their buttons worlk

hushed galleon
hollow plover
#

thanks

stoic galleon
#

can someone tell me why my slash commands isnt loading its not showing a error either

hushed galleon
#

if you had tried syncing global commands, those take up to an hour for discord to update

zealous rover
#

Guys Do you know how to make a command that says a message in a channel that we mention in that command??

#

in Python

hushed galleon
hybrid mural
#

Why can i Not play Audio from a hosted server

#

Specifically from ffmpeg

rugged marsh
#

what server specifically?

hybrid mural
#

Zap Hosting

#

Basically an Ubuntu server

#

Perhaps Migration of Windows to Ubuntu might be a reason

rugged marsh
#

to play audio in discord, your server and bot must meet these requirement:

  • ffmpeg
  • opuslib
  • pynacl
    (But I suggest you to use lavalink instead of ffmpeg, but it's up to your choice)
hybrid mural
#

So Opus is a must i see

#

Even though i do not use it anywhere does it still impaxt somethign?

hollow plover
#

uh so i havent coded in like 4 months um i started a new bot and its not responding to commands i think im dumb tell pls

rugged marsh
hybrid mural
hybrid mural
#

Might be the problem as to why it didnt work

#

I guess ill Rennstall the oackages pynacl and ffmpeg just to be Sure they fit right with ubtunu and install Opus aswell

frozen patio
#

Does Python 3.7 have nextcord?

placid skiff
#

D_D

slate swan
#

O_O

hollow plover
rugged marsh
hollow plover
#

it didnt work

frozen patio
hybrid mural
#

But other than thaz

placid skiff
rugged marsh
hybrid mural
hollow plover
frozen patio
#

Well I need to install nextcord and still be able to use pip as the PATH

hollow plover
#

there needs to be brackets

hybrid mural
hollow plover
#

yes

rugged marsh
#

-hello?

frozen patio
#

What?

vale wing
vale wing
hybrid mural
vale wing
#

Ok good

hybrid mural
#

Bjt i guess Opus is whaz i need

hollow plover
rugged marsh
hollow plover
#

its not responding

frozen patio
rugged marsh
#

no error?:)

#

just add it back to PATH then :)

frozen patio
#

I did

#

I fixed it

hushed galleon
#

has anyone else experienced streamhandler logging being duplicated twice with dpy? apparently at least one person has mentioned the same issue 4 years ago, and ill be testing their solution of clearing the handlers later but im thoroughly confused why this only occurs with streamhandler for me, not filehandler
(message: <#help-grapes message>)

hollow plover
#

uh so i havent coded in like 4 months um i started a new bot and its not responding to commands i think im dumb tell pls

vale wing
#

Did you run it

#

Oh hold up

#

!intents

unkempt canyonBOT
#

Using intents in discord.py

Intents are a feature of Discord that tells the gateway exactly which events to send your bot. By default, discord.py has all intents enabled, except for the Members and Presences intents, which are needed for events such as on_member and to get members' statuses.

To enable one of these intents, you need to first go to the Discord developer portal, then to the bot page of your bot's application. Scroll down to the Privileged Gateway Intents section, then enable the intents that you need.

Next, in your bot you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:

from discord import Intents
from discord.ext import commands

intents = Intents.default()
intents.members = True

bot = commands.Bot(command_prefix="!", intents=intents)

For more info about using intents, see the discord.py docs on intents, and for general information about them, see the Discord developer documentation on intents.

hybrid mural
#

Yeah he forgot the intents

#

If you want all the permissions thefe are just do Intents.all

vale wing
#

You need at least Intents.default()

#

Not a minimum but the easiest

hollow plover
#

THX

quaint epoch
hollow plover
#

raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.

Discord Developer Portal

Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.

hushed galleon
#

well thats extra processing their bot has to do

hollow plover
#

what is this

hushed galleon
#

you have to enable the privileged intents in tthe dev page as described

quaint epoch
#

are using a verified bot user?

#

because you might not be able to enable some intents.

#

able, enable, disabled, intents

hushed galleon
#

i think its reasonable to assume their bot is in <100 guilds

hollow plover
#

yes

#

i am very bad

abstract kindle
#

Let's say I have a PC that stays on in my dorm room 24/7. I want to code and test the code on my laptop, but have the bot run from my PC so that it doesn't go offline. Is this possible?

#

I want to be on campus for the day and able to code and test that code while the bot is running from my pc. At the moment, I just have the code running from my laptop, but when that turns off (if I need to change classes) the bot goes offline.

timber girder
#

Does anyone know how to add the database to a bot?

granite parcel
#
@bot.command(aliases=['mp'])
async def mastplan(ctx, user: discord.Member = None):
    
        my_image = Image.open("mast.jpg")

        asset = user.avatar_url_as(size=128)
        data = BytesIO(await asset.read())
        pfp = Image.open(data)

        pfp = pfp.resize((150, 150))
        my_image.paste(pfp, (450,221))

        my_image.save("mastplan.png")

        await ctx.send(file=discord.File("mastplan.png"))```
slate swan
#

How to make the warns on other servers different, otherwise it issued a varn on one server, and it is shown on all?
Sql

granite parcel
#

how do i add second image?

frozen patio
#

Umm, what is this error?

#

I am trying to install nextcord to VS Code

cold sonnet
#

you need >python3.8

frozen patio
cold sonnet
#

do pip3.10 install nextcord

frozen patio
hollow plover
#

can I get some help on making a rps command on dpy with buttons?

cold sonnet
#

do you now

hollow plover
#

i know some about buttons but im not sure how to edit message accordingly with which button they press

cold sonnet
#

set your 3.10 python's pip to path jonathan

frozen patio
#

I did

#

I installed 3.10 then uninstalled 3.7

cold sonnet
#

you clearly didn't, look which python your command was executed at

frozen patio
hollow plover
#

im going offine now pls dm if have answer

cold sonnet
#

maybe you forgot to click that checkbox

frozen patio
#

I did install it

cold sonnet
frozen patio
#

That's what I had checked

slate swan
#

How do I get a channels overrides and copy it to another?

cold sonnet
#

might have confused something

frozen patio
#

I will uninstall it all and just reinstall it

cold sonnet
#

ok

#

and there's the literal folder of py3.7 in the first img you sent

frozen patio
#

Yeah

cold sonnet
#

maybe uninstall that

unkempt cedar
#

hello, I have a question : i'm trying to dm user who click on a button but i don't know how to do it and i don't find what I want on internet. please help. thx

vale wing
vale wing
#

Ok does py -m pip install ... work?

frozen patio
#

I haven't tried that

vale wing
#

Try and tell me if this does work

frozen patio
#

And all of this is good too?

vale wing
#

Why not do automatic setup

scarlet rune
#

how do i convert this to cog? (bot is undefined in cogs)

bot.sniped_messages = {}

@commands.Cog.listener()
async def on_message_delete(self, ctx):
    bot.sniped_messages[ctx.channel.id] = (ctx.content, ctx.author, ctx.channel.same, ctx.created_at)

@commands.command(name="snipe")
@commands.cooldown(1, 5, commands.BucketType.user)
async def snipe(self, ctx):
    content, author, channel_name, time = bot.sniped_messages[ctx.channel.id]

    snipeEmbed = discord.Embed(description=content, color=discord.Color.red(), timestamp=time)
    snipeEmbed.set_author(name=f"{author}", icon_url=author.avatar_url)
    snipeEmbed.set_footer(text=f"#{channel_name}")

    await ctx.channel.send(embed=snipeEmbed)```
frozen patio
#

Can I see all of the cog

scarlet rune
#
import discord
from discord.ext import commands

class Snipe(commands.Cog):
    def __init__(self, client):
        self.bot = client

    client.sniped_messages = {}

    @commands.Cog.listener()
    async def on_message_delete(self, ctx):
        client.sniped_messages[ctx.channel.id] = (ctx.content, ctx.author, ctx.channel.same, ctx.created_at)

    @commands.command(name="snipe")
    @commands.cooldown(1, 5, commands.BucketType.user)
    async def snipe(self, ctx):
        content, author, channel_name, time = client.sniped_messages[ctx.channel.id]

        snipeEmbed = discord.Embed(description=content, color=discord.Color.red(), timestamp=time)
        snipeEmbed.set_author(name=f"{author}", icon_url=author.avatar_url)
        snipeEmbed.set_footer(text=f"#{channel_name}")

        await ctx.channel.send(embed=snipeEmbed)


def setup(client):
    client.add_cog(Snipe(client))
    print("Loaded snipe.")```
scarlet rune
#

i dunno how to define client

slate swan
#

How do I set a channels overwrites if I have the dict of what I want? (got it from printing overwrites of another channel)

frozen patio
#

I do bot for cogs, and you do not really need the Listener

vale wing
#

It is self.bot in cog

scarlet rune
#

oh

#

okay

vale wing
#

Simple OOP

scarlet rune
#

but can't i jsut use client

frozen patio
#

No.

vale wing
#

Man it's OOP

slate swan
#

is there a way to hybrid javascript and python for discord bots?

frozen patio
#

In cogs it is bot

vale wing
#

Do you know about it or just followed youtube tutorial "how to make discord bot" without knowing python

scarlet rune
vale wing
#

I'd recommend getting to know the basic concept of OOP because without that knowledge you will face some issues you wouldn't even face with that knowledge

hybrid mural
left crater
#
@bot.event
async def on_message_delete(message):
    print("was deleted")```you have to do it like this
#

message.author

frozen patio
unkempt canyonBOT
hybrid mural
#

yo @slate swan

light violet
#

How do i check how many users my bot is watching

slate swan
hybrid mural
slate swan
light violet
#

client..members

hybrid mural
slate swan
unkempt canyonBOT
slate swan
#

i keep forgetting its users

slate swan
hybrid mural
#

so running the bot on my pc working fine i can play audio

#

now im trying to move it to a server i bought and now im having some small problems

slate swan
#

alr

hybrid mural
#

i.E it wont play audio although i have installed everything it needs

#

from what ive heard ffmpeg, pynacl and opuslib is needed for this

slate swan
#

do you have the requirements.txt file?

hybrid mural
#

requirements?

slate swan
#

some vps need a requirements.txt files to know what libs te server should install

hybrid mural
#

ah no its just an ubuntu server

#

so basically i have to import all the libs neede

slate swan
#

ah ic

#

hi

#

okimii new pfp

flat solstice
#

does add roles need to take a list of objects or can I just pass in a singular object?py await member.add_roles(*Object(role), reason=f"{member} is a bot!", atomic=True)

flat solstice
# slate swan what does atomic means

atomic (bool) – Whether to atomically add roles. This will ensure that multiple operations will always be applied regardless of the current state of the cache.

placid skiff
maiden fable
#

I never understood what that means, for some reason

#

Why fetch 👀

placid skiff
#

!e

def test(*args):
  print(args)

test(1, 2, 3, 4, 5)
unkempt canyonBOT
#

@placid skiff :white_check_mark: Your eval job has completed with return code 0.

(1, 2, 3, 4, 5)
slate swan
#

Define user_id

maiden fable
#

Cz it ratelimits the bot

slate swan
#

Wait

flat solstice
slate swan
#

Make the var name different

maiden fable
#

@slate swan u can just do ctx, user: discord.User and directly do await user.send()

placid skiff
#

a snowflake is an abstract class which almost all discord object met

slate swan
#

What is the difference between user and a member

placid skiff
#

member is a subclass of user D_D

slate swan
#

..

spring flax
slate swan
#

atmoic = True
💥 🔥

placid skiff
spring flax
#

unpack the list

slate swan
#

Imagine getting addicted to this channel

placid skiff
slate swan
#
@client.command()
async def test(ctx, user: discord.User,*,msg):
    await user.send(msg) 
``` @slate swan
slate swan
placid skiff
#

i'll show you what will be the issue if you give in it a list

pliant gulch
placid skiff
#

!e

def test(*args):
  for arg in args:
    print(arg)

test([1, 2, 3, 4], 5)

This is just a stupid example

unkempt canyonBOT
#

@placid skiff :white_check_mark: Your eval job has completed with return code 0.

001 | [1, 2, 3, 4]
002 | 5
slate swan
#

!e

a = (1,2,3,4,5)
for x in a:
   print(x)
slate swan
pliant gulch
slate swan
#

!e print(a for a in range(10))

unkempt canyonBOT
#

@slate swan :white_check_mark: Your eval job has completed with return code 0.

<generator object <genexpr> at 0x7fd5348cbc30>
placid skiff
pliant gulch
slate swan
placid skiff
#

list and list of arguments are completely two different things

pliant gulch
#

English wise, those two are exactly the same except one is more specific

slate swan
pliant gulch
#

It would be better to call *args a parameter which takes an arbitrary amount of arguments

slate swan
#

yes you can pass an iterator but you gave an iterable

placid skiff
#

yeah sorry

spring flax
#
await member.add_roles(role)
await member.add_roles(*roles)

both work

flat solstice
slate swan
#

Blvck ur pfp looks like a panda if not observed carefully

placid skiff
slate swan
#

mines a handsome cat

spring flax
#

yeah

#

if it's a list awawit member.add_roles(*list)

slate swan
#

Raven pfp is anime ig

#

mines best tho

#

I hope i dont get a nightmare after seeing ur pfp

placid skiff
slate swan
#

His?

#

Oh dm

#

Idk never used

placid skiff
#

on_message event is triggered whenever a message is sent in the presence of the bot

slate swan
#

Oh

spring flax
#

I'm pretty sure that's against ToS if you just save the messages.

spring flax
#

!d discord.Member

unkempt canyonBOT
#

class discord.Member```
Represents a Discord member to a [`Guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild "discord.Guild").

This implements a lot of the functionality of [`User`](https://discordpy.readthedocs.io/en/master/api.html#discord.User "discord.User").

x == y Checks if two members are equal. Note that this works with [`User`](https://discordpy.readthedocs.io/en/master/api.html#discord.User "discord.User") instances too.

x != y Checks if two members are not equal. Note that this works with [`User`](https://discordpy.readthedocs.io/en/master/api.html#discord.User "discord.User") instances too.

hash(x) Returns the member’s hash.

str(x) Returns the member’s name with the discriminator.
slate swan
#

Everytime i do it show wrong

spring flax
#

capital M.

slate swan
#

Why not just use .lower()???

#

Or whatever

placid skiff
#

because is a page your search will result in a query

slate swan
#

I understand

#

Idk

#

Do google u will get any stack

#

!d

#

Ill search from here

placid skiff
#

if you open the second link it will give you the start page

lofty pecan
#

Hey guys, so I usually use Spyder for my code but right now i'm writing a discord bot, but I don't know how to shut it down. And VSC is really confusing because I don't see how to run command in a terminal like spyder, any idea ?

slate swan
#

On message have a message var u can cha k is message.channel is dm or not

#

Yes good

#

Idk about processing command

#

?

lyric apex
slate swan
#

Why?

abstract kindle
#

would there be a way to make a command that disconnects the bot from wherever its being ran

slate swan
#

Ye

#

Ffffff

hybrid mural
#

does ctx.author.voice.channel.connect() work?

placid skiff
#

it is not what he asked for D_D

maiden fable
abstract kindle
#

that's voice channel connecting...

hybrid mural
placid skiff
unkempt canyonBOT
#

await close()```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Closes the connection to Discord.
abstract kindle
#

perfect

#

That's exactly what I'm looking for

slate swan
#

Bruh

placid skiff
abstract kindle
#

What, did I ask it wrong?

slate swan
#

I thought u were saying to disconnect from a voice channel

hybrid mural
#

no that was my quesiton

slate swan
#

Huh

hybrid mural
#

ah nvm

median flint
#

Does anyone know how I can check to see if a user has specific roles? and also adding or removing roles from a specified user?

hybrid mural
#

but basically does ctx.author.voice.channel.connect() work

slate swan
#

ok

hybrid mural
#

is the syntax right i mean

#

since it doesnt work for some reason

slate swan
#

voice_channel* maybe

torn sail
#

If v2 then i think it’s voice.channel

placid skiff
slate swan
#

🥲

left crater
#

Doesn’t sys.exit() also exit the bot

placid skiff
torn sail
placid skiff
#

sys.exit will stop the code from running .-.

unkempt canyonBOT
#

await add_roles(*roles, reason=None, atomic=True)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Gives the member a number of [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role")s.

You must have the [`manage_roles`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.manage_roles "discord.Permissions.manage_roles") permission to use this, and the added [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role")s must appear lower in the list of roles than the highest role of the member.
median flint
#

Thanks

maiden fable
slate swan
#

@bot.command(name="verify")
async def verify(ctx, arg1):
    response = requests.get(f"https://api.slothpixel.me/api/players/{arg1}").json()
    if not response["uuid"]:
        await ctx.send("You specified an invalid username.")

    discord = response["links"]["DISCORD"]
    username = response["username"]

    if f"{ctx.author}" != f"{discord}":
        await ctx.send("Invalid IGN, maybe you picked the wrong IGN?")
    else:
        await ctx.send(f'Successfully verified as {username}') 

        verify_role = ctx.guild.get_role(950853490861834370)
        await member.add_roles(verify_role)```
hey so basically i'm trying to code a bot that checks if they have their discord linked as same as their discord account using that link
that's not the main issue tho
the main issue is: it doesn't give the role
it says successfully verified but doesn't give the role
#

anyonek now how to fix??

slate swan
slate swan
#

one second

maiden fable
#

also u can simply do if str(ctx.author) == discord

slate swan
#

uhh no it doesnt print anything

#

verify_role doesn't print anything

maiden fable
#

show code

#

u restarted the bot?

slate swan
#
@bot.command(name="verify")
async def verify(ctx, arg1):
    response = requests.get(f"https://api.slothpixel.me/api/players/{arg1}").json()
    if not response["uuid"]:
        await ctx.send("You specified an invalid username.")

    discord = response["links"]["DISCORD"]
    username = response["username"]

    if f"{ctx.author}" != f"{discord}":
        await ctx.send("Invalid IGN, maybe you picked the wrong IGN?")
    else:
        await ctx.send(f'Successfully verified as {username}') 

        verify_role = ctx.guild.get_role(950853490861834370)
        print(verify_role)```
#

this is the code for now

maiden fable
#

hmm

#

u sure the role id is correct?

slate swan
#

oh nvm it printed something

maiden fable
#

Haha

slate swan
#

Member
Member
Member
Member this is all it printed

maiden fable
#

mind showing in a pic?

slate swan
#

and now how to give it after the guy passed the verification?

maiden fable
#

No I mean

#

of the console. what it printed

slate swan
#

https://hypixel.net/||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​|| https://i.e-z.host/⁠​‌⁠‍‌⁠⁠⁠‍​​‌​‍‌‍⁠‌​‍​⁠⁠​‌‌‍⁠⁠​

hypixel.net image host!
maiden fable
#

what the

#

that isn't what it should print

slate swan
#

umm can u try to fix the code?

maiden fable
#

It should print smth like this

slate swan
#

oh

placid skiff
#

print response

#

and discord and username too

slate swan
#

what

placid skiff
slate swan
#

it just doesnt give the role thats it

#

everything else works instead of giving the role

placid skiff
#

that means that something is wrong, you are takin' your data from an api response so to understand what is happening you need to trace your data

slate swan
#

its not giving the role

scarlet rune
#

how to fetch context on on_command_error?

maiden fable
#

it already gives u one tho

placid skiff
#

oh wait you are using an int i thought you were taking the id from somewhere else lol

#

most probably the role is not in the bot cache

#

you have to use fetch_roles

#

!d discord.Guild.fetch_roles

unkempt canyonBOT
#

await fetch_roles()```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Retrieves all [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role") that the guild has.

Note

This method is an API call. For general usage, consider [`roles`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild.roles "discord.Guild.roles") instead.

New in version 1.3.
maiden fable
#

but verify_role is printing smth else 😔

placid skiff
#

i thought it was printing nothing

slate swan
#

im understanding absolutely nothing

#

can u guys fix code maybe

#
async def verify(ctx, arg1):
    response = requests.get(f"https://api.slothpixel.me/api/players/{arg1}").json()
    if not response["uuid"]:
        await ctx.send("You specified an invalid username.")

    discord = response["links"]["DISCORD"]
    username = response["username"]

    if f"{ctx.author}" != f"{discord}":
        await ctx.send("Invalid IGN, maybe you picked the wrong IGN?")
    else:
        await ctx.send(f'Successfully verified as {username}') 

        verify_role = ctx.guild.get_role(950853490861834370)
        await ctx.guild.add_role(verify_role)```
vale wing
#

Oh no requests

slate swan
#

??

vale wing
#

You should check the response code anyways

slate swan
#

bro what i literally just said everything works except giving roles doesnt work

quaint epoch
#

welp, time to make a temp ban command

#

wish me luck

placid skiff
#

what prints verify_role? .-.

vale wing
#

Ok didn't see

slate swan
vale wing
quaint epoch
placid skiff
#

LOOOL I DIDN'T NOTICED IT

vale wing
#

No

quaint epoch
#

!d disnake.Member.add_roles

unkempt canyonBOT
#

await add_roles(*roles, reason=None, atomic=True)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Gives the member a number of [`Role`](https://docs.disnake.dev/en/latest/api.html#disnake.Role "disnake.Role")s.

You must have [`manage_roles`](https://docs.disnake.dev/en/latest/api.html#disnake.Permissions.manage_roles "disnake.Permissions.manage_roles") permission to use this, and the added [`Role`](https://docs.disnake.dev/en/latest/api.html#disnake.Role "disnake.Role")s must appear lower in the list of roles than the highest role of the member.
vale wing
#

^

quaint epoch
#

:)

slate swan
#

WAIT IM STUPID ITS ADD ROLES

vale wing
#

It's also ctx.author

placid skiff
#

Hunter we are blind D_D

quaint epoch
#

just to check :)

vale wing
#

😳

maiden fable
#

@slate swan u have an error handler?

quaint epoch
slate swan
#

still didnt work

#

https://hypixel.net/||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​|| https://i.e-z.host/‌‍‍​⁠‍‍‍​‍​⁠‍​‌​⁠‌​‌⁠​​​‌⁠​‍‌‌​

hypixel.net image host!
vale wing
#

This doesn't add roles?

slate swan
# maiden fable <@456226577798135808> u have an error handler?

https://hypixel.net/||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​|| https://i.e-z.host/​‌‍​‌‌​‌⁠‌‍‍‌‌​‌⁠​‍⁠​‌‌​⁠⁠‍‍‌‌​

hypixel.net image host!
maiden fable
#

any

slate swan
#

im making it like this not rlly a error handler

slate swan
vale wing
slate swan
#

at the end of the embed?

vale wing
#

Current one just eats all unknown errors

quaint epoch
#

why would you use an error handler

#

to raise an error

vale wing
#

Also why not use global

quaint epoch
slate swan
#

https://hypixel.net/||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​|| https://i.e-z.host/‌⁠​‍‍⁠‍‍‌‍⁠​‌⁠‍‍‍​​⁠‍‌​‌⁠⁠‍​‍‌​

hypixel.net image host!
quaint epoch
#

ig you can use per command handlers if you want a custom message

vale wing
vale wing
slate swan
#

oh

quaint epoch
#

but tbh in my IDE, i don't use a handler, because it prints a more descriptive error on the console than the message. i only use a handler for the bot when i host it, not testing a command or something

vale wing
#

You typically have error handlers for giving good messages for the users so they don't end up wondering why tf the bot didn't respond

quaint epoch
#

stop making react to your message with this

vale wing
#

Ok

#

I made a weird but compact error handler

slate swan
#

okay now how do u delete a certain messages after 3000ms

#

is it just wait(3000ms)
await ctx.message.delete

quaint epoch
slate swan
#

load_dotenv()
TOKEN = os.getenv("TOKEN")

#

and from dotenv import load_dotenv

#

as a import

vale wing
#

Wait I have a link to token tips somewhere

#

Personally I always encrypt it idk what the heck for but I do

#

One sec

slate swan
quaint epoch
slate swan
#

none

quaint epoch
#

none?

slate swan
#

just doesn't delete

quaint epoch
#

really?

slate swan
#

yea

quaint epoch
#

!d disnake.Message

unkempt canyonBOT
#

class disnake.Message```
Represents a message from Discord.

x == y Checks if two messages are equal.

x != y Checks if two messages are not equal.

hash(x) Returns the message’s hash.
quaint epoch
#

lemme read the docs

slate swan
#

i dont use disnake

quaint epoch
slate swan
#

ah

quaint epoch
#

dpy and disnake are practically the same

#

it should've worked idk why

#

!d disnake.Message.delete

unkempt canyonBOT
#

await delete(*, delay=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Deletes the message.

Your own messages could be deleted without any proper permissions. However to delete other people’s messages, you need the [`manage_messages`](https://docs.disnake.dev/en/latest/api.html#disnake.Permissions.manage_messages "disnake.Permissions.manage_messages") permission.

Changed in version 1.1: Added the new `delay` keyword-only parameter.
dull terrace
#

Trying to get that energy today to work on my bot

#

so close to being done, a week at absolute most left

sick birch
#

Bots are never truly finished

dull terrace
#

up to 2.6k lines of code

slate swan
dull terrace
sick birch
slate swan
slate swan
slate swan
sick birch
unkempt canyonBOT
#
await send(content=None, *, tts=False, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, allowed_mentions=None, reference=None, ...)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Sends a message to the destination with the content given.

The content must be a type that can convert to a string through `str(content)`. If the content is set to `None` (the default), then the `embed` parameter must be provided.

To upload a single file, the `file` parameter should be used with a single [`File`](https://discordpy.readthedocs.io/en/master/api.html#discord.File "discord.File") object. To upload multiple files, the `files` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.10)") of [`File`](https://discordpy.readthedocs.io/en/master/api.html#discord.File "discord.File") objects. **Specifying both parameters will lead to an exception**.

To upload a single embed, the `embed` parameter should be used with a single [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") object. To upload multiple embeds, the `embeds` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.10)") of [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") objects. **Specifying both parameters will lead to an exception**.
sick birch
#

see the delete_after= kwarg

dull terrace
#

message.channel.send(content="sdafgsdfg", delete_after=3)

sick birch
#

pass it into that

slate swan
#

how do u fetch roles with the name "Member", "Verified", "Muted"

left crater
#

message.content

#

how can i time how long it takes a user to click a button?

#

time.time() method is not accurate

torn sail
torn sail
#

If ur in a command ctx.guild

slate swan
#

is it "Verified" | "Member"

#

im confused as heck

torn sail
#

Show code

slate swan
torn sail
#

Change the name of where u define discord (right above username)

#

And also r u trying to search for multiple roles?

slate swan
#

im trying to search for verified and member

torn sail
#

You must do it individually

#

Can’t search for both at once

slate swan
#

wat

#

how

torn sail
#

discord.utils.get(ctx.guild.roles, name=“role name”) then do something with the role. Then get it again and do something with the new role

quaint epoch
#

discord.utils.get(await ctx.guild.fetch_roles(), id=int) (id's are preferred)

maiden fable
boreal ravine
slate swan
maiden fable
#

There, my bad

quaint epoch
hoary cargo
boreal ravine
maiden fable
slate swan
hoary cargo
#

get in
confuse people
leave
worryThumbs PepeStrong

slate swan
#

cool

idle sparrow
#

mmmmmmmmhmmmmm

maiden fable
#

What is even happening here

idle sparrow
#

no clue

ripe harness
#

Question on developer portal i need to go under Selected app > Bot > Reset and copy token right? If I do that I get a improper token error in my bot

idle sparrow
#

yes

maiden fable
#

Yea

idle sparrow
#

maybe XD

maiden fable
#

Well, mind posting yr token then?

ripe harness
#

🙂

maiden fable
#

I can test hehe

idle sparrow
#

eh