#discord-bots

1 messages ยท Page 739 of 1

soft lynx
#

true

potent spear
#

are you creating some kind of menu?

cloud dawn
#

!pypi disnake

unkempt canyonBOT
soft lynx
potent spear
#

never said that either...

#

fill in the gaps and I'll try to help

soft lynx
#

when you use option 8 as an argument, a menu pops up

#

thats just how it works

#

but, ill give more context

potent spear
#

idk, never seen it, I guess you're using a specific library

slate swan
potent spear
robust ridge
#

im tryna troll my server but my code aint workin

slate swan
robust ridge
#
@client.command()
async def fga(ctx):
    guild = ctx.guild 
    users = ctx.guild.members
    for user in users:
        while True:
            try:
                await user.send("poo1")
                print("Message sent to: " + user.name)
            except:
                print("Couldn't send to: " + user.name)
#

it spams only 1 person

slate swan
#

i havent used python

robust ridge
#

...

potent spear
soft lynx
potent spear
robust ridge
slate swan
robust ridge
#

i switched to vscode from pycharm yesterday

potent spear
final iron
potent spear
# soft lynx

never used discord_components, and I also don't advice you using that
gl!

soft lynx
potent spear
robust ridge
#

i changed the while true

#

so it doesnt spam

#

since its against tos

silver magnet
#

any way i can make a python code choose a random string out of a list?

#

im using it for a bot

unkempt canyonBOT
#

random.choice(seq)```
Return a random element from the non-empty sequence *seq*. If *seq* is empty, raises [`IndexError`](https://docs.python.org/3/library/exceptions.html#IndexError "IndexError").
robust ridge
#

random.choices

silver magnet
#

ah

final iron
elfin smelt
elfin smelt
final iron
robust ridge
#

no everyone in my server

#

a troll but its only gonna send a msgg 5 times

#

and ill say bot got hacked

final iron
#

Mhm

#

I'm not going to help with that

robust ridge
#

๐Ÿ’€๐Ÿ’€๐Ÿ’€๐Ÿ’€

final iron
#

Finished my custom commands

#

That was extremely easy

#

Now time for customization

silver magnet
#
import random
from discord.ext import commands

print(discord.__version__)

client = commands.Bot(command_prefix="or!")
TOKEN = "token in here"

@client.event
async def on_ready():
    print("logged as {0.user}".format(client))


@client.command()
async def ping(ctx):
    await ctx.channel.send(f"In milliseconds: {round(client.latency * 1000)}")

@client.command()
async def dice(ctx):
    await ctx.channel.send(f"Here is your number: {random.randrange(1, 6)}")

client.run(TOKEN)

the commands don't seem to work

#

nvm

#

i figured out whats wrong

slate swan
#

and use a f string on ready

silver magnet
#

on_ready works without f string

#

and when i do add it shows an error

final iron
#

What's the error?

#

It shouldn't be giving one

#

Unless you're doing something like f"{0.user.client}"

slate swan
#

Can someone help with Discord bots?

slate swan
#

thats what the channel is meant for :V

#

I need someone to build it for me - Mass invite bot looks great but really want to be careful so it doesn't spam people. I'd like to target specific server groups but have it drip feed.

slate swan
#

Oh wow! Didn't know that - I'm constantly being slammed by what i believe are bots so thought that was just normal in Discord

sour inlet
#

does anyone know how to get client references from an extension?

#

I have a ping command I want to put in an extension but it needs Client.latency()

slate swan
#

What is a good bot to use to grow a channel?

sour inlet
#

oh ty

sour inlet
slate swan
potent spear
sour inlet
#

oh so I have to turn it into a cog?

potent spear
#

sure, it's for the better

slate swan
#

just use ctx.bot.latency if its a command

sour inlet
#

cool thanks

potent spear
#

yeah, using ctx to get the bot object is also perfectly possible

sour inlet
#

yeah that works

final iron
sour inlet
#

thanks again everyone!

slate swan
slate swan
slate swan
green bluff
#

how do i get a persons user

#

username when he / she does the command

#

like !hi

#

in terminal it would say

slate swan
#

ctx.author

green bluff
#

hi executed by -----

#

thanks

slate swan
#

yw

green bluff
#

how do i message a member

#

like say !message @abwduhawd

#

and it dms them

slate swan
#

you send the dm to the author

green bluff
#

but the author is me

#

and i dont want it to send to me

slate swan
#

ah then use a member arg

green bluff
#

yup i did

slate swan
#

member: discord.Member

green bluff
#

how do i phrase it

#

so that it would dm them

slate swan
#

with a kwarg

green bluff
#

sooo

#

how?

#

like i wanna do ctx.message (member)

slate swan
#
await member.send(msgkwarg)
green bluff
#

thanks

slate swan
#
async def command(ctx , member : discord.Member):
  # now you can use any property/method `member` has
  # .send() method is used to send a message
#

ez

green bluff
#

yup thanks aswell

slate swan
#

he wants to send a msg to a member

slate swan
#

!sendtomember something
and it dms the member that msg

green bluff
#

so

#

i have a suggestion reason here

#

how do i put that

#

into this

#

like i want the reason to be displayed in there

#

actually that might be too complicated

#

idk

heavy folio
#

why is title=""

#

you need a db ig

green bluff
#

im thinking what to write

slate swan
#

@green bluff example of it

@client.command()
async def command(ctx, member: discord.Member = None, *, msg="empty") -> typing.Optional[discord.Message]:
    if not member:
        return("need to add a member")
    await member.send(msg)
final iron
#

Is there something built in to check my bots uptime or would I have to do it myself with a bot var?

green bluff
#

i dont understand the code

slate swan
#

just a simple example

green bluff
#

dont get it tho im bad at this

final iron
#

So lets say I use the command
!command @Water_Gazes#2352 Wow, you're looking particularly spicy today.

#

The @Water_Gazes#2352 part will be assigned to member which gets type hinted in to a member object

frank tartan
#
@client.command()
async def toggleDM(ctx, status):
    author_id = ctx.author.id
    if status == "enable":
        client.noDM_list.remove(author_id)
        await ctx.reply("You can now recieve dm's from me.")
    elif status == "disable":
        client.noDM_list.append(author_id)
        await ctx.reply("You can no longer recieve dm's from me.")
    else:
        await ctx.reply("Please put either `disable` or `enable`")

is my code.
I have 2 questions

  1. Is it possible to store the information in like a text document, or like a spreadsheet instead of a list

  2. if so, how?

slate swan
#

since the lists content will be removed on restart

final iron
#

^

#

I would recommend sqlite3

slate swan
final iron
#

^

slate swan
#

!pypi aiosqlite

unkempt canyonBOT
frank tartan
slate swan
#

look up lol

final iron
final iron
#

Its an interactive website for learning sql

#

I personally learnt it in 2-3 days but everyone will be different

frank tartan
slate swan
final iron
slate swan
#

ill speedrun it tomorrow lol

slate swan
final iron
#

For a discord bot you don't really need to go through the entire thing

slate swan
#

yeah

final iron
#

I've already made custom commands with my "limited knowledge"

slate swan
#

you just have to know how to add and pull data mostly

final iron
#

Yeah

final iron
#

Really all you need to know is SELECT, the WHERE clause (and the operators), INSERT INTO, REPLACE INTO and maybe a bit about creating tables

final iron
#

Never heard of it

slate swan
#

and FROM ofc

final iron
#

FROM is included with SELECT

#

Cant learn SELECT without FROM

potent spear
slate swan
slate swan
final iron
frank tartan
#

@final iron im only on lesson 2 and my brain already wants to quit lol

slate swan
#

only gets authors with no duplicates

#

if a movie has the same author it will not get it if theyres already a movie with it

final iron
#

In what situations have you used that?

slate swan
#

but it is helpful

final iron
#

I don't see a use case for me (yet)

#

All I've made with my db is pp commands (funny haha), custom prefix and custom commands

#

Also my error handler

#

I log unhandled errors in to my database so I can view them later

frank tartan
#

bruhhh i cant get passed lesson 2

final iron
slate swan
#

@final iron

SELECT DISTINCT author FROM movies;

table looks like

# movie table
author: movies

john : coolmovie1
john : coolmovie2
bob : coolmovie3

will only show

author

john
bob
frank tartan
slate swan
frank tartan
#

so ima be afk while i watch a yt video about it

slate swan
#

goodluck with that๐Ÿšถ

final iron
#

And suggestion system

#
    @commands.Cog.listener('on_member_join')
    @commands.is_owner()
    async def blacklist_dm_check(self, member: disnake.Member):
#

What was I smoking when I made this

slate swan
#

๐Ÿšถ

final iron
#

How would I see how many commands I have?

barren fog
final iron
#

I would assume there is something that returns all the commands in a list?

final iron
barren fog
#

hm

slate swan
#

disnake here mostly

barren fog
#

ok thanks

pliant gulch
slate swan
#

!d disnake.ext.commands.Bot.commands

unkempt canyonBOT
#

property commands: Set[disnake.ext.commands.core.Command[disnake.ext.commands.core.CogT, Any, Any]]```
A unique set of commands without aliases that are registered.
slate swan
#

thats cool never knew

final iron
#

56 commands so far

#

Its getting up there

#

Still haven't subclassed my help command kekw

slate swan
#

me with a command named help: ๐Ÿƒ

barren fog
slate swan
final iron
slate swan
#

would love to see how much generals here use next cord or dpy

#

i use disnake ofc

final iron
#

I also use disnake py_guido

barren fog
#

is it different ๐Ÿคจ

final iron
#

How often can I change my bots status?

#

How many requests a minute

pliant gulch
#

120

final iron
#

oh shit

slate swan
final iron
#

Thats a lot

pliant gulch
#

Because I literally recoded my websocket handler for gateway

slate swan
pliant gulch
final iron
#

I'll just change it every 30 seconds

pliant gulch
#

You're just gonna waste bandwith by doing that

#

Do you really need it to update every 30 seconds

final iron
#

Nope

#

How often would you recommend?

pliant gulch
#

Once per minute is enough

final iron
#

Can I have the docs on changing your status?

pliant gulch
#

!d discord.Client.change_presence

unkempt canyonBOT
#

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

Changes the clientโ€™s presence.

Example

```py
game = discord.Game("with the API")
await client.change_presence(status=discord.Status.idle, activity=game)
```   Changed in version 2.0: Removed the `afk` keyword-only parameter.
final iron
#

Thanks

barren fog
#

!d how to hack discord

slate swan
pliant gulch
# pliant gulch Once per minute is enough

Do keep in mind, when sending change presence payloads to the websocket your bot will NOT receive any other events from the gateway until the presence is finished sending

#

So you would be blocking your bot from events 1 every 60 mins for x seconds

#

So maybe a bit higher than 1 minute

final iron
#

Probably sounds dumb, but how would cycle through different statuses?

green bluff
#

how do i add it so u can only do !suggest once until u get approved

#

@slate swan

slate swan
green bluff
#

okimi can u help with mine

slate swan
slate swan
green bluff
#

wait

#

so when i run the command i give the user a role?

slate swan
#

wait i think you dont understand

green bluff
#

i think i do

slate swan
#

give a role that is used as a whitelist for the command

pliant gulch
unkempt canyonBOT
#

@pliant gulch :white_check_mark: Your eval job has completed with return code 0.

001 | 0
002 | 1
green bluff
#

yeah thats what i thought

#

but how do i whitelist

halcyon sparrow
#

did discord add buttons already?

green bluff
#

people with that role

slate swan
green bluff
#

how would i do that

slate swan
slate swan
#

i think thats the decorator im not sure

green bluff
#

and the role would be in quotation i assume

green bluff
#

yup lemme give it a try

slate swan
unkempt canyonBOT
#

@disnake.ext.commands.has_role(item)```
A [`check()`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.check "disnake.ext.commands.check") that is added that checks if the member invoking the command has the role specified via the name or ID specified.

If a string is specified, you must give the exact name of the role, including caps and spelling.

If an integer is specified, you must give the exact snowflake ID of the role.

If the message is invoked in a private message context then the check will return `False`.

This check raises one of two special exceptions, [`MissingRole`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.MissingRole "disnake.ext.commands.MissingRole") if the user is missing a role, or [`NoPrivateMessage`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.NoPrivateMessage "disnake.ext.commands.NoPrivateMessage") if it is used in a private message. Both inherit from [`CheckFailure`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.CheckFailure "disnake.ext.commands.CheckFailure").

Changed in version 1.1: Raise [`MissingRole`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.MissingRole "disnake.ext.commands.MissingRole") or [`NoPrivateMessage`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.NoPrivateMessage "disnake.ext.commands.NoPrivateMessage") instead of generic [`CheckFailure`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.CheckFailure "disnake.ext.commands.CheckFailure")
slate swan
#

item takes a str or a int

#

str as the name of the role or a int as the id

green bluff
#

wait so i can create a variable

#

for that

slate swan
#

no

green bluff
#

and if its true

slate swan
#

no

green bluff
#

okay what do i do

slate swan
#

A check() that is added that checks if the member invoking the command has the role specified via the name or ID specified.

#

@commands.has_role("rolename")

#

or use the id

green bluff
#

ok

#

and do i write 'rolename'=false

#

?

slate swan
#

no

#

if the check failed it will not continue

#

and if they do have it, it will continue

green bluff
#

but then i have like a 20 roles in my serber

#

do i have to list every single role

#

in that check

#

is there like a does.not.have_role

slate swan
#

ig check if the author has the role and if they do return a msg and if they dont it will continue

green bluff
#

howo would i do

#

can i do if commands,has_role('awdawd') is false:

#

continue

slate swan
# green bluff howo would i do
for role in ctx.author.roles:
    if role.name == "rolename":
        return await ctx.send("cannot use this command")
#keep doing stuff

im not sure if this would work idk

quick gust
green bluff
slate swan
quick gust
#

who's gonna put it inside a function lol

green bluff
slate swan
unkempt canyonBOT
#

Indentation

Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.

Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.

Example

def foo():
    bar = 'baz'  # indented one level
    if bar == 'baz':
        print('ham')  # indented two levels
    return bar  # indented one level

The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.

Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines

More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation

green bluff
#

how did this get an error

slate swan
#

look at your command on the top

#

or whatever you have on the top

#

which will cause an error there

spring flax
#

hello. I have a cog but it keeps saying that commands in it cannot be found when the commands are invoked

spring flax
#

!paste

quick gust
#
  1. is it loaded properly?
  2. make sure there isn't that common indent problem and the commands are actually inside the subclass
green bluff
quick gust
#

it wasn't for u

green bluff
#

not to me ik but what u said before

#

ik

slate swan
#

@spring flax your missing self

 @commands.command()
    #@commands.check_any(commands.is_owner(), commands.has_role())
    async def edit(rule, ctx, message : disnake.Message, *,new_content : str):
        if not message.embeds:
            await message.edit(content=new_content)
        else:
            embed = message.embeds[0]
            embed.description = new_content
            await message.edit(embed=embed)

and setup should not be in the class

green bluff
#

@slate swan

quick gust
#

damn okimii faster

slate swan
#

im speedpithink

#

im acceleration

quick gust
#

I'm light

slate swan
green bluff
quick gust
#

...

slate swan
#

to literal

green bluff
#

?

slate swan
# green bluff ?

i ment what you have on the top of that command thats giving the error

green bluff
#

oh i was stupid

#

also @slate swan

#

i finished

slate swan
#

nice

green bluff
#

gonna check if it works

slate swan
#

did you loaded the cog?

quick gust
#

Same error? And does only this cog not work?

spring flax
green bluff
#

@slate swan it says i suggested the command but it also says i cant use it

slate swan
green bluff
#

i gave myself the suggest role btw

slate swan
# green bluff

the for loop i gaved is to check if the author has a black listing role

untold token
#

You could use discord.utils.find method in here

slate swan
#

never used utils๐Ÿšถ

quick gust
#

haven't seen you in a while

green bluff
#

i dont know what u mean

untold token
green bluff
#

would thios work

untold token
#

!d discord.utils.find

slate swan
green bluff
unkempt canyonBOT
#

discord.utils.find(predicate, seq)```
A helper to return the first element found in the sequence that meets the predicate. For example:

```py
member = discord.utils.find(lambda m: m.name == 'Mighty', channel.guild.members)
```  would find the first [`Member`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member "discord.Member") whose name is โ€˜Mightyโ€™ and return it. If an entry is not found, then `None` is returned.

This is different from [`filter()`](https://docs.python.org/3/library/functions.html#filter "(in Python v3.9)") due to the fact it stops the moment it finds a valid entry.
quick gust
green bluff
#

i meant to say ** I tried it and it definitely doesnt wokr**

untold token
#

Error?

green bluff
#

im just saying can i do something to make it work

#

nope no error

untold token
#

Hmm did you pass the reason?

green bluff
#

@commands.cooldown(1, 600, commands.BucketType.user)
async def suggest(ctx, *, reason=None):

  if reason is None:
    await ctx.reply("Please enter a suggestion.")
  else:
    for role in ctx.author.roles:
        if role.name == "suggest":
            return await ctx.send("cannot use this command")
        else:
            embed = discord.Embed(title="",
            description=f"**Suggestion** : {reason}",
            colour=discord.Colour.orange())
            embed.set_author(name=f'{ctx.author}s Suggestion.', icon_url=ctx.author.avatar_url)
            channel = client.get_channel(928950254798258196)
            await ctx.channel.purge(limit=1)
            await channel.send(embed=embed)
            embed = discord.Embed(title="**Suggestion sent!**: ",
            description=f"**{reason}** | You will be dmed once a decision is made.",
            colour=0xFFFFFF)
            await ctx.author.send(embed=embed)```
untold token
#

and are you the server administrator?

green bluff
#

ye

final iron
untold token
slate swan
untold token
#

You should use command checks instead

heavy folio
untold token
#

!d discord.ext.commands.check

unkempt canyonBOT
#

@discord.ext.commands.check(predicate)```
A decorator that adds a check to the [`Command`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Command "discord.ext.commands.Command") or its subclasses. These checks could be accessed via [`Command.checks`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Command.checks "discord.ext.commands.Command.checks").

These checks should be predicates that take in a single parameter taking a [`Context`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Context "discord.ext.commands.Context"). If the check returns a `False`-like value then during invocation a [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure") exception is raised and sent to the [`on_command_error()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.discord.ext.commands.on_command_error "discord.discord.ext.commands.on_command_error") event.

If an exception should be thrown in the predicate then it should be a subclass of [`CommandError`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CommandError "discord.ext.commands.CommandError"). Any exception not subclassed from it will be propagated while those subclassed will be sent to [`on_command_error()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.discord.ext.commands.on_command_error "discord.discord.ext.commands.on_command_error").
heavy folio
#

also it's a bad method to loop through author.roles and look for it

green bluff
#

whats tha

heavy folio
#

simply use utils.get()

final iron
slate swan
untold token
#

command checks are special decorators that check for a condition before the command starts

green bluff
#

please give me the code i dont get where u want me to put utils.get

#

im new to all this

untold token
green bluff
#

just tell me then

heavy folio
#

wdym where to put utils.get

green bluff
#

where would i put that

#

in my code

final iron
heavy folio
#

wdym where???

untold token
#

Yes

heavy folio
#

!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.

Examples

Basic usage...
untold token
#
from itertools import cycle

statusesโ€‹ย โ€‹=โ€‹ย โ€‹cycleโ€‹(["...", "..."])  #  statuses here

@โ€‹tasksโ€‹.โ€‹loopโ€‹(โ€‹minutesโ€‹=โ€‹12โ€‹)
asyncโ€‹ย โ€‹defโ€‹ย โ€‹status_changeโ€‹(): 
 โ€‹ย ย ย ย ย ย ย ย โ€‹awaitโ€‹ย โ€‹botโ€‹.โ€‹wait_until_readyโ€‹() 
 โ€‹ย ย ย ย ย ย ย ย โ€‹awaitโ€‹ย โ€‹botโ€‹.โ€‹change_presenceโ€‹(โ€‹activityโ€‹=โ€‹discordโ€‹.โ€‹Gameโ€‹(โ€‹nextโ€‹(โ€‹statusesโ€‹)))
green bluff
#

i trried to write it myself i got an error how can i fix it?

final iron
untold token
final iron
#

This is another prime example of why you should learn python before jumping in to a discord bot

green bluff
#

OH WAIT IK

final iron
#

!d discord.Guild.roles

unkempt canyonBOT
#

property roles: List[discord.role.Role]```
Returns a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of the guildโ€™s roles in hierarchy order.

The first element of this list will be the lowest role in the hierarchy.
final iron
#

It returns a list

#

You need to pass in a role

#

Or can you pass in a list?

#

Idk

slate swan
#

or have a black listing role as i said

green bluff
#

@slate swan

#

it works so

slate swan
green bluff
#

how do i remove roles

#

from the person

slate swan
#

like that iirc

green bluff
#

it doesnt remove the role tho

slate swan
#

can your bot remove roles?

green bluff
#

lemme rety

#

it has admin perms

slate swan
#

!d discord.Member.remove_roles

unkempt canyonBOT
#

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

Removes [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role")s from this member.

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 removed [`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.
slate swan
#

and is the bot role higher than the one you will remove?

green bluff
#

i changed it just now lemme try again

#

no it doesnt remove his role no errors either

#
@client.command()
async def approve(ctx, member: discord.Member):
    role = discord.utils.get(ctx.guild.roles, name='suggest')
    embed=discord.Embed(title=f'Your suggestion has been approved by **{ctx.author}!**', description='Thank you for helping build our community!', colour=0x00FF00)
    await member.send(embed=embed)
    await ctx.author.remove_roles(role)
slate swan
#

your trying to remove the role from yourself btw

green bluff
#

OH ya

#

i realised that rn

slate swan
#

lol

green bluff
#

im the author

slate swan
#

yes

final iron
#

Because that's what he's doing

slate swan
final iron
#

Me neither

slate swan
#

lol

final iron
#

!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.

Examples

Basic usage...
final iron
#

You can

slate swan
#

ic

final iron
#

Should I make an economy system?

#

I'm kinda on the fence

#

I don't see a reason to make an economy system when dank memer has a monopoly but I feel it would be fun

slate swan
final iron
#

Heh

#

Wat

slate swan
#

you can store any type of currencies and you can make transactions with the money (buy ranks/roles) and can make converters that converts the currencies to other currencies

final iron
#

Why would I make multiple currencies

#

Seems too complicated to do all that conversion

slate swan
final iron
#

Rpg game when?

slate swan
#

good idea

royal oar
#

Would anyone know how to make a bot play an audio file in a channel.i can make the bot join and play but then I have to get it to leave and rejoin.

final iron
#

I'll just start with basic economy shit

#

Deposit, Rob, hunt, job and all that jazz

#

Being creative is going to be hard

#

Wrong server

verbal plinth
#

๐Ÿ‘

final iron
#

Wait you were actually in the wrong sever lmao

verbal plinth
#

wait what?

slate swan
#

๐Ÿšถโ€โ™‚๏ธ any bot name ideas?

slate swan
final iron
#

I called mine WaterBoat

#

Very amazing name

slate swan
slate swan
#

more like , testing hikari

final iron
slate swan
final iron
#

I already have boat

#

And my stupid ass hard coded the footers icons

slate swan
#

how about i name it ramen

final iron
#

Why not

slate swan
#

with a ramen avatar

#

name it ganbare

#

๐Ÿ˜ณ

#

nice idea ๐Ÿ˜ณ

#

๐Ÿƒ

final iron
#

I stole my bots pfp off Google

#

Not the best idea

slate swan
#

same

#

i got sued

#

๐Ÿƒ

royal oar
#

Oof

#

I need to change mine then๐Ÿ˜‚

final iron
#

If my bot gets bigger I'll contact someone to make my own

slate swan
#

but you can

royal oar
slate swan
#

copyright lol

#

๐Ÿƒโ€โ™‚๏ธ well if its anime or smthing it doesnt matter

slate swan
#

i have rias in the pfp of my personal private bot๐Ÿ˜ณ

royal oar
slate swan
#

i hab kakashi

slate swan
#

tho i dont work on it now

final iron
#

Imma go to sleep now

#

Ping me with command ideas

slate swan
#

no

final iron
#

๐Ÿƒ

slate swan
#

make a command that gives command ideas๐Ÿง 

final iron
slate swan
#

.topi

#

.topic

lament depotBOT
#
**What's one feature you wish more developers had in their bots?**

Suggest more topics here!

slate swan
#

LMAO

slate swan
#

seen it

slate swan
#

๐Ÿ”ช

#

๐Ÿƒ

#

.topic

#

SMH๐Ÿ˜ 

#

aw

spring flax
#

I have a cogs, I'm trying to load them by using ```py
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
bot.load_extension(f'{filename[:-3]}')

#

but it keeps saying extension 'test' has no setup function, (test.py is the cog name)

slate swan
#

it does not have a set function as the error says

#

doesnt it speak for itself?

#

you probably made it inside the cog class lol

spring flax
#

let me send it here one second

slate swan
#

maybe it tried to load a py file which isnt a cog

#

The error says all.

spring flax
#

!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.

spring flax
#

i hope i didn't do something dumb

slate swan
#

You need to add

def setup(bot):
    bot.add_cog(YourCogClass(bot))

at the end of each cog.

slate swan
#

def setup(bot):
    bot.add_cog(Test(bot))
#

No init function

spring flax
#

i did that, outside the class

slate swan
#

It's

def __init__

and not

def init
#

bruh def init ๐Ÿ˜ญ

#

thats a magic method/dunder ๐Ÿ˜ญ

spring flax
#

do cogs need to be in a folder or can they be in the same folder as the main code just another file?

spring flax
#

i mean right now i just have one cog

slate swan
#

so it will loop through all the files in that directory which end with .py so in that case yes they should be in a separate folder so you wont load you main file or other files

spring flax
#

i can't just load a cog like bot.load_extension('test') ?

slate swan
spring flax
#

or can i just create a new file

slate swan
#

!d discord.ext.commands.Bot.load_extension

unkempt canyonBOT
#

load_extension(name, *, package=None)```
Loads an extension.

An extension is a python module that contains commands, cogs, or listeners.

An extension must have a global function, `setup` defined as the entry point on what to do when the extension is loaded. This entry point must have a single argument, the `bot`.
slate swan
#

welp im going to go to sleep Gn guyspithink

cold lion
#

im trying to set up my discord bot to read how many players are online in one of my gaming servers any ideas?

tender estuary
#
@client.event
async def on_member_leave(member):
    channel = discord.utils.get(member.guild.channels, id=733201139478036501)
    embed=discord.Embed(title=f"Goodbye,{member.name}.", description=f"{member.name} has left {member.guild.name}.")
    embed.set_thumbnail(url=member.avatar_url)
    await channel.send(embed=embed)
    await member.send(embed=embed)

What's wrong with this? It does not do what its supposed to do.

slate swan
#

Well, what does it do ๐Ÿคท

tender estuary
#

Its supposed to send an embedded message to a specific channel when someone leaves the server.

#

It is not doing anything, no errors.

slate swan
#

Have you enabled the Members Privileged Intent in the developer portal and in your code?

tender estuary
#

yes

slate swan
#

May you show?

tender estuary
#

sure

slate swan
#

Just to make sure ^^

tender estuary
#
intents = discord.Intents.all()
intents.members = True

client = commands.Bot(command_prefix = 'v!', case_insensitive=True, intents=intents)
#

this is what's in my code

slate swan
#

It's case_insensitive just as side note.

tender estuary
barren fog
#

please

slate swan
#

!d discord.on_member_remove

unkempt canyonBOT
#

discord.on_member_join(member)``````py

discord.on_member_remove(member)```
Called when a [`Member`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member "discord.Member") leaves or joins a [`Guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild "discord.Guild").

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

welp, I have tried on_member_remvoe

#

it does not work either

slate swan
#

Well try it now at least.

tender estuary
#

sure

slate swan
#

on_member_leave will never work as it doesn't exist.

slate swan
#

because your trying to dm a member that left a guild and if that member doesnt have mutual guilds with the bot it wouldnt dm the member afaik

tender estuary
tender estuary
slate swan
tender estuary
#

Personal opinion, discord.py feels like something entirely different than python to me xD

slate swan
#

It's a Python library, so there's nothing different to Python when you're using discord.py :)

slate swan
#

A try/except should be nothing new to you.

tender estuary
#

it isn't

#

I did it, I am removing the bot from the host atm

#

Updating it is too long

#

of a process

#
@client.event
async def on_member_remove(member):
    try:
        channel = discord.utils.get(member.guild.channels, id=733201139478036501)
        embed=discord.Embed(title=f"Goodbye,{member.name}.", description=f"{member.name} has left {member.guild.name}.")
        embed.set_thumbnail(url=member.avatar_url)
        await channel.send(embed=embed)
        await member.send(embed=embed)
    except:
        print("Did not work")
    finally:
        pass
#

The output was Did not work

slate swan
#

print the error if any

tender estuary
#

nope

#

no error

slate swan
#

then it wont dm the user

tender estuary
#

but wait

#

it actually worked

#

but still the output at the terminal was Did not work

#

huh

slate swan
tender estuary
#

weird

slate swan
dusty vale
#

im playing around with dis-snek and added slash commands, when trying to use it though, the menu is freaking out. anyone ever seen something like this and has any idea?

slate swan
dusty vale
#

nah i let another guy test it and he has the same

#

i can "fix" it by kicking the bot and reinviting it, but every new command i add is causing this again

slate swan
#

thats weird never seen it happen before

tender estuary
#

I want the owner of the server to have a command that allows him to set a on_member_join role. How do I do it?

tender estuary
#

Let me tell you how it will work,
v!set_member_join_role <role here>
so now whenever someone joins the server they get this role automatically.

spring flax
#

for a command check like

def something():
    def predicate(ctx):

for the parts where it lets them use the command, i should write return True, and for the parts where it should not let the user use the command it's return False right

slate swan
tender estuary
#

I have tried that, But how do I use the same var in the on_member_join event?

tender estuary
#

I guess this is what you meant by that

#

I guess it has something to do with decorators?

tender estuary
#
@client.event
async def on_member_join(member):
    channel = client.get_channel(733201137615765616)
    embed=discord.Embed(title=f"Welcome {member.name}.", description=f"Thanks for joining {member.guild.name}!")
    embed.set_thumbnail(url=member.avatar_url)
    await channel.send(embed=embed)
    await member.send(embed=embed)
    await member.add_roles(member.guild.get_role(854387380278919238))
``` I simply can't think of a connection between that command and this event.
slate swan
#

how to keep your bot online forever

tender estuary
#
    await member.add_roles(member.guild.get_role(854387380278919238))
``` Here I want the id given here to be the role I just returned in the given command.
slate swan
tender estuary
slate swan
slate swan
#

gnu*

tender estuary
#

heroku works just fine for me

slate swan
slate swan
#

it returns a role doesnt it

#

idk what u saying

tender estuary
#

Still don't get how it will help in any way.

tender estuary
#
await member.add_roles(member.guild.get_role(set_on_join_role()))
``` You mean this?
slate swan
#

how does discord dev api work, why doesn't it need open ports

slate swan
unkempt canyonBOT
#

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

hello world
slate swan
#

the function returns a value which in this case its a str

tender estuary
#

Its just that I want to confirm everything before I do. If I mess things up that will be a BIG mistake

slate swan
#

yeah

tender estuary
#
 role_ = discord.utils.get(ctx.guild.get_role(role))

retuned error

#

TypeError: 'NoneType' object is not iterable

slate swan
#

role is none

tender estuary
#

I'll try using converter

slate swan
#

hm was @unkempt canyon made with dpy

tender estuary
#

no, dpy was made with python

slate swan
#

@unkempt canyon bot

unkempt canyonBOT
#
Command Help

!bot
Bot informational commands.

slate swan
#

dude

slate swan
tender estuary
#

Ohhh

slate swan
#

!bot

unkempt canyonBOT
#
Command Help

!bot
Bot informational commands.

tender estuary
#

Shit sorry

#

yeah probably

slate swan
unkempt canyonBOT
slate swan
#

As you can see, yes.

spring flax
#

there's nothing wrong with this code right?

def permission_check():
    def predicate(ctx):
        if (discord.utils.find(lambda r: r.id == 873148465956417576, ctx.author.roles)) and ctx.channel.id == 929989647046696990: 
            return True
        else:
            return None
    return commands.check(predicate)
tender estuary
#

Uhm what are you trying to do here

slate swan
#

Why return None?

#

Return False in the opposite case.

spring flax
#

doesn't return None raise the missing permission check failure?

unique tendon
#

My bot suddenly stopped working and i have no idea why

#

I didnt change anything and it just suddenly says error

strong vessel
#

Let it rest for a bit maybe it's temporary server error

unique tendon
#

I dont know what this means

unique tendon
strong vessel
#

Oh it's blocking ip

unique tendon
#

I got rate limited?

strong vessel
#

Wherever your server is hosted is getting blocked by discord due to heavy traffic

unique tendon
#

How the hell

slate swan
strong vessel
#

Probably some spammer using repl

unique tendon
#

oh

slate swan
#

yeah

unique tendon
#

Ok so should I transfer code to another repl?

slate swan
#

does that change the ip?

unique tendon
#

No idea

#

I dont think so

strong vessel
#

If you don't mind it you could try waiting it out

unique tendon
#

Lemme try anyways atleast i know whats the problem now thanks

#

So basically someone hacked my repl?

slate swan
#

no

unique tendon
#

Or is spamming traffic on it?

slate swan
#

repl shares ips

strong vessel
#

No someone else using repl is spamming discord

unique tendon
#

Oh ok

#

so its not my fault

slate swan
slate swan
unique tendon
#

Kk ig

#

ill try waiting then

quick gust
#

your fault is using replit

sweet geyser
slate swan
sweet geyser
unique tendon
slate swan
strong vessel
slate swan
quick gust
unique tendon
#

Ok

slate swan
#

replit shares ip smh

unique tendon
#

I got so scared lmao

#

Itโ€™s in my server with 1.5k

slate swan
#

is there any simple module to implement nlp for my bot?

unique tendon
#

i dont wanna risk anything

slate swan
#

lol

#

your good

sweet geyser
#

Use heroku

slate swan
#

like i want to use the message and want the bot to reply it

#

like discortics

unique tendon
#

Or what

sweet geyser
#

Yep its hosting

unique tendon
#

Cuz i got repl hacker thats why im using it

#

For 24/7 hosting

slate swan
#

not even ment for discord bots

#

why not just host in repl?

#

for free

unique tendon
tender estuary
unique tendon
slate swan
#

use ovpn

#

have you guys read my msg and others msgs?

unique tendon
quick gust
tender estuary
unique tendon
#

Idk what to do at this point except waiting

quick gust
slate swan
#

or use uprobot

unique tendon
#

It doesnt let me turn on my bot

slate swan
slate swan
quick gust
#

alot

slate swan
#

me rn:
๐Ÿšช ๐Ÿšถ

tender estuary
#

Can anyone explain in brief what cogs are?

slate swan
slate swan
#

am i missing something ?

heavy folio
slate swan
zinc horizon
#

Does anyone know the correct syntax to send a message in chat with a matched phrase? My code doesn't recognize when I use the word in a sentence.

marble blaze
#

how to grant roles to members
eg for add_roles

heavy folio
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.
zinc horizon
# heavy folio wdym by that

When I was coding the bot, it would only respond to the word if it was not in a sentence. I wasn't using the split method. So, that part is okay now. But now the bot will not ignore itself and spams the channel.

slate swan
#

why isn't my bot getting ratelimited?

#

sends around 50 messages / minute

#

on 100 servers

#

50*100 = too fucking much

heavy folio
#

because the lib handles ratelimits for you

slate swan
#

huh

#

I mean it just keeps sending bro it aint gettin ratelimited

#

dont write

#

just by seeing ur name

#

dont write anything

heavy folio
heavy folio
quick gust
slate swan
#

Will ignore all bots which is much better and not just the bot itself

quick gust
#

ooh

#

good to know

slate swan
#

someone with a, well weird name

slow fog
fervent shard
#

is there like a one line code that removes roles that have send_messages permissions? if so, could you please share it with me? (discord.py)

stable mulch
#

Hello

slate swan
cold lion
#

i play scum and im trying to get my discord bot to read how many players are currently online, any help?

cold lion
#

yeah

fervent shard
slate swan
#

iterate thru Guild.members and check if Member.status is online , idle or dnd

slate swan
#

Role.permissions.send_messages would be true if member has the perms

leaden jasper
#

how to turn discord ID to username#1234 if the user is not in ur server?

slate swan
#

!d discord.ext.commands.Bot.get_user

unkempt canyonBOT
slate swan
#

get the user . and use str(user)

stable mulch
#

I've got an idea that I would like to share with you guys :)

Imagine, a Discord bot that simulates an economy system, based off of real life economy. A bot that let's you create shops, sell items to other users, plant your own virtual crops in Discord. Basically, a bot that simulates real life to some extent in Discord (think of it as a type of roleplay)!

What do you think?

cold lion
#

so do I do this through the battlemetrics site or would i do it through my servers ip?

slate swan
#

and will also be a lot of work

tiny ibex
#

How to get the url of a mp4 file

pseudo lake
slate swan
#

how is that related to a game

stable mulch
slate swan
unkempt canyonBOT
#

The attachment URL. If the message this attachment was attached to is deleted, then this will 404.

cold lion
#

so im an admin of my own scum server. which is a game. id like to make a discord bot that shows my discord server how many players are currently in the game.

slate swan
tiny ibex
stable mulch
#

Would you guys like to check it out? I can create a server with the bot in it.

slate swan
unkempt canyonBOT
cold lion
#

im super new to this so im sorry if im not explaining right.

slate swan
cold lion
slate swan
#

scum has something like a game server?

cold lion
#

yeah scum has multiple servers. you can rent your own

cold lion
slate swan
cold lion
#

yes! so battlemetrics has an api ive looked through but im not exactly sure how to read it all

cold lion
#

thank you so much

small igloo
#

how to use py await open_account(user)?

#

is dat exist or no

cold lion
#

this is the server we own. and the player count is what i want to show

slate swan
#

.topic

lament depotBOT
#
**What feature would you be the most interested in making?**

Suggest more topics here!

small igloo
slate swan
cold lion
#

this is so hard XD

slate swan
small igloo
slate swan
#

So continue the tutorial you're following, then it will be done ^^

slate swan
#

I mean it might be hard for them, but the language isn't hard

cold lion
#

yeah i feel like its simple im just making it super hard. ive never taken any kind of coding and just kinda jumped into this today

slate swan
#

'this' โ‰  hard

slate swan
slate swan
small igloo
slate swan
#

As I said:

So continue the tutorial you're following, then it will be done ^^

cold lion
#

nah lol. butttt i did get my bot to say hello back to me lol

small igloo
unique tendon
#

I need help coding a command, idk how to code it but i have the idea in my head

unkempt canyonBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

slate swan
#

tbh I have no idea when I learnt python, I just kinda learnt it somehow

small igloo
slate swan
#

not in school

#

Take a look at this @unique tendon

slate swan
small igloo
unique tendon
#

I might be asking for too much so nvm

slate swan
fervent shard
#
@bot.command()
@commands.has_permissions(kick_members=True)
async def mute(ctx, member: discord.Member, *, reason=None):
    if member == ctx.author:
        em = discord.Embed(
            description=f"**you** cannot `mute` yourself", colour=discord.Colour.red()
        )
        await ctx.send(embed=em)
 
    else:
        guild = ctx.guild
        mutedRole = discord.utils.get(guild.roles, name="muted")
        role = discord.utils.get(ctx.guild, name='๐ŸŒผ | owner', '๐Ÿ”ฎ | co-owner', '๐Ÿ”ฅ | moderator', '๐Ÿฎ | rich', '๐Ÿค– | streamer','๐Ÿงผ | personal assistant', '๐ŸŽ€ | girls', '๐Ÿ’Ž | boys')
        await user.remove_roles(role)
        em1 = discord.Embed(
            description=f"{member.mention} has been `muted` for **{reason}**",
            colour=discord.Colour.green(),
        )
 
    em2 = discord.Embed(
        description=f"**you** have been `muted` for **{reason}**", colour=0
    )
    await ctx.send(embed=em1)
    await member.send(embed=em2)
    list_of_muted_members.append(member)
    print(list_of_muted_members)```
theres an error, could anyone help?
slate swan
#

whats the error

#

What is the error ยฏ_(ใƒ„)_/ยฏ

small igloo
fervent shard
# slate swan whats the error
    role = discord.utils.get(ctx.guild, name=':blossom: | owner', ':crystal_ball: | co-owner', ':fire: | moderator', ':cow: | rich', ':robot: | streamer',':soap: | personal assistant', ':ribbon: | girls', ':gem: | boys')
                                                             ^
SyntaxError: positional argument follows keyword argument```
heavy folio
#

because you cant do that?

slate swan
#
role = discord.utils.get(ctx.guild, name='๐ŸŒผ | owner', '๐Ÿ”ฎ | co-owner', '๐Ÿ”ฅ | moderator', '๐Ÿฎ | rich', '๐Ÿค– | streamer','๐Ÿงผ | personal assistant', '๐ŸŽ€ | girls', '๐Ÿ’Ž | boys')
await user.remove_roles(role)

This will never work

heavy folio
#

!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.

Examples

Basic usage...
slate swan
#

You can't remove roles like that as you wish.

fervent shard
heavy folio
#

you can do await user.remove_roles(Role1, Role2, Role3) but nto role = discord.utils.get(ctx.guild, name=':blossom: | owner', ':crystal_ball: | co-owner', ':fire: | moderator', ':cow: | rich', ':robot: | streamer',':soap: | personal assistant', ':ribbon: | girls', ':gem: | boys')

#

oh god

small igloo
slate swan
#

Untrue

#

Either you skipped a video, or it's in the next video.

small igloo
#

also why pay for winrar

slate swan
#

So if you blindly follow a tutorial without knowing what the code does or anything similar, then at least entirely follow the tutorial.

#

or dont follow it

small igloo
slate swan
#

read docs then try stuff

#

tutorials not good for learning

vocal ivy
#

i think you should do some basic python things first and then code the bot

slate swan
slate swan
cold lion
#

does this server do any kind of on hands help?

small igloo
vocal ivy
#

dont jump into doing it immediately

slate swan
slate swan
slate swan
#

literally

#

the syntax is just english

#

You directly stopped after you got that error, so continue the tutorial and look at previous videos of the series.

unique tendon
#

I want to make a command, so if I do .verify @near osprey, itll give the person the community role

slate swan
#

@bot.command()
@commands.has_permissions(kick_members=True)
async def mute(ctx, member: discord.Member, *, reason=None):
if member == ctx.author:
em = discord.Embed(
description=f"you cannot mute yourself", colour=discord.Colour.red()
)
await ctx.send(embed=em)

else:
    guild = ctx.guild
    mutedRole = discord.utils.get(guild.roles, name="muted")
    role = discord.utils.get(ctx.guild, name='๐ŸŒผ | owner', '๐Ÿ”ฎ | co-owner', '๐Ÿ”ฅ | moderator', '๐Ÿฎ | rich', '๐Ÿค– | streamer','๐Ÿงผ | personal assistant', '๐ŸŽ€ | girls', '๐Ÿ’Ž | boys')
    await user.remove_roles(role)
    em1 = discord.Embed(
        description=f"{member.mention} has been `muted` for **{reason}**",
        colour=discord.Colour.green(),
    )

em2 = discord.Embed(
    description=f"**you** have been `muted` for **{reason}**", colour=0
)
await ctx.send(embed=em1)
await member.send(embed=em2)
list_of_muted_members.append(member)
print(list_of_muted_members)
cold lion
#

i feel like im not going to code or use python much after this. so i was wondering if this server has somewhere that will just show me how to do this.

slate swan
slate swan
rocky mist
cold lion
#

fair enough

rocky mist
slate swan
rocky mist
unique tendon
#

I want to make a command, so if I do .verify @example, itll give the person the community role

vocal ivy
slate swan
rocky mist
#

i didn't import that trash?

slate swan
#

Not you, the outdated library you're using imports it :p

rocky mist
slate swan
#

Update all the libraries you're using.

#

And don't use deprecated libraries.

fervent shard
slate swan
#

That will never work.

#

You need to use get_role or similar functions.

fervent shard
slate swan
#
x = ...get_role(role_id)
x1 = ...get_role(role_id)
...

await member.remove_roles(x, x1)
fervent shard
slate swan
#

No.

#

It's a variable..

#

You need to get roles based on their ID, not name.

#

You can't just do

await member.remove_roles("name 1", "name 2")
#

They need to be Role objects.

#

!d discord.Role

unkempt canyonBOT
#

class discord.Role```
Represents a Discord role in a [`Guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild "discord.Guild")...
slate swan
#

And get_role gives you a role object back.

unkempt canyonBOT
#

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

unique tendon
#

How to make it so if someone does .verify @1234, the person mentioned is given a role

#

@slate swan

slate swan
#

Add a parameter in your command and type hint it to discord.Member.
Then you can use get_role(role_id) and assign it to a variable.
Then you can use add_roles(var) to give the member the role.

unique tendon
#

Confusion

#

Ok nvm

fervent shard
pseudo lake
pseudo lake
#

dont copy paste code without knowing/understanding what it does

#

use discord.utils

fervent shard
pseudo lake
#
from discord.utils import get

role_id = 123
role = get(guild.roles, id=role_id)```
#

you could do that, altho i dont suggest it since its overwriting some python namespace

#

!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.

Examples

Basic usage...
pseudo lake
slate swan
#

!d discord.Guild.get_role

unkempt canyonBOT
slate swan
#

Replace ... in ....get_role(883538063496708116) with a Guild object. Something like message.guild or ctx.guild, depending on where you have the code.

vale glen
#

is it possible to embed a video into an embed

slate swan
#

No.

vale glen
#

ok

rustic kayak
#

Hey uhh I am new to discord.py and I need to build a bot that deletes a channel if the channel name starts with something, is that possible? I think that's theoritically possible but I have no idea how to even code it

slate swan
#

Yes it is.

glad thicket
#

hey can you help me

slate swan
#

When do you want to do that? Upon channel creation or using a command?

rustic kayak
#

Upon using a command

slate swan
#

Then you need to loop through all the channels in the guild -> guild.channels.
And check if the channel.name starts with what you want, then you can use channel.delete() to delete it.

glad thicket
#
import discord
from discord.ext import commands
from pokemontcgsdk import Card
from pokemontcgsdk import RestClient

bot = commands.bot('&')

if os.path.isfile('.env'):
    load_dotenv('.env')
else:
    pass

RestClient.configure(os.environ['api_token'])
token = os.environ['token']

@bot.command(name="ptcg", brief="pokemon tcg card finder", description="Finds the card that matches the id \nex** xy1-1")
async def ptcg(ctx: commands.Context, id):
    card = Card.find(id)
    embed = discord.Embed(colour=0x03fcad, 
                  title=f"{card.name} {card.nationalPokedexNumbers}", 
                  description=f"type: {card.types}\nweakness: {card.weaknesses}")
    embed.set_image(url=card.image.large)
    embed.add_field(name="Moves [for now only 1 is dsiplayed]", 
                    value=f"{card.attacks.Attack.name} | {card.attacks.Attack.text} | {card.attacks.Attack.cost} | {card.attacks.Attack.damage}")
    embed.add_field(name="Other Info",
                    value=f"series: {card.series}\nrarity: {card.rarity}\nRelease Date: {card.releaseDate}")
    await ctx.send(embed=embed)

bot.run(token)```
heavy folio
unkempt canyonBOT
#

discord.on_guild_channel_delete(channel)``````py

discord.on_guild_channel_create(channel)```
Called whenever a guild channel is deleted or created.

Note that you can get the guild from [`guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.GuildChannel.guild "discord.abc.GuildChannel.guild").

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

oh

#

why upon using a command tho

slate swan
#

And you need to pass command_prefix="&"

glad thicket
#

ok I fixed that

#

but the embed is not showing when I type &pktcg xy1-1 @slate swan

rustic kayak
slate swan
glad thicket
rustic kayak
slate swan
#

I won't waste my time at looking at it if you already fixed it..

glad thicket
#

the code isn't working

slate swan
#

then its not fixed

glad thicket
#

even though I did what you told me too

oblique adder
#
from nextcord import colour, embeds
from nextcord.ui import view
import nextcord
from nextcord.ext import commands

class Button(nextcord.ui.View):
    def __init__(self):
        super().__init__(timeout=None)

    @nextcord.ui.button(
        label='1', 
        style=nextcord.ButtonStyle.green,
        custom_id="first")
    async def first_button(self, button: nextcord.ui.Button, interaction : nextcord.Interaction):
        print("first button click")
    
    @nextcord.ui.button(
        label ="2",
        style=nextcord.ButtonStyle.secondary,
        custom_id="second")
    async def second_button(self , button : nextcord.ui.Button, interaction: nextcord.Interaction):
        print("second button click")

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

    @commands.command()
    async def testb(self,ctx):
        await ctx.send("test", view = Button())
def setup(bot: commands.Bot):
    bot.add_cog(Test(bot))```

how do I make te 2nd button below the 1st one instead of being beside it ?
slate swan
#

Don't think you can.

#

Or eventually a 2 dimensional list of buttons.

oblique adder
rustic kayak
#
import discord


class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        if message.author == self.user:
            return

        if message.content == 'clean':
            async def complete(ctx):
                guild = None  # grab all guild from server that match
                id_admin = discord.Role.id = None
                overwrites = {
                    id_admin: discord.PermissionOverwrite(send_messages=True),
                    guild.me: discord.PermissionOverwrite(read_messages=True),
                }
                for i in guild.channels:
                    if i.channel.name.startswith(''):
                        await i.delete()


client = MyClient()
client.run('')```
I got this far only, please help ;-;
slate swan
#

Sending your message again won't change anything.

rustic kayak
slate swan
#

And as I said it's just channel.delete()

rustic kayak
#

a bad one

rustic kayak
unkempt canyonBOT
#

nextcord.ui.button(*, label=None, custom_id=None, disabled=False, style=<ButtonStyle.secondary: 2>, emoji=None, row=None)```
A decorator that attaches a button to a component.

The function being decorated should have three parameters, `self` representing the [`nextcord.ui.View`](https://nextcord.readthedocs.io/en/latest/api.html#nextcord.ui.View "nextcord.ui.View"), the [`nextcord.ui.Button`](https://nextcord.readthedocs.io/en/latest/api.html#nextcord.ui.Button "nextcord.ui.Button") being pressed and the [`nextcord.Interaction`](https://nextcord.readthedocs.io/en/latest/api.html#nextcord.Interaction "nextcord.Interaction") you receive.

Note

Buttons with a URL cannot be created with this function. Consider creating a [`Button`](https://nextcord.readthedocs.io/en/latest/api.html#nextcord.ui.Button "nextcord.ui.Button") manually instead. This is because buttons with a URL do not have a callback associated with them since Discord does not do any processing with it.
slate swan
#

See the row argument

#

First button with row=0, second with row=1