#discord-bots

1 messages · Page 548 of 1

hasty iron
#

it calls the api if the user isnt cached

proud glade
#

oh really?

#

haven't used dpy in months, closing an year

#

i've forgotten that tbh

#

.split("#")

#

pretty sure member returns it as username#discriminator

valid niche
#

you're doing split before the for loop, so you're splitting a list

#

not a single member's name

#

also not sure why you're trying to use name#discriminator

#

that's like a very inefficient way of going about it

#

just check the member ID

#

i reccomend to not use username/discriminator at all

slate swan
#

^

#

use the user's id

valid niche
#

so your typehinting will get the list of users, enter the for loop, for every user get their ID and look it up in the guild.bans

#

or not even guild.bans, use guild.fetch_ban(id)

slate swan
#

^

valid niche
#

no name, no split

#

just ID, and guild.fetch_ban(id)

proud glade
#

name and discriminator are subject to change at anytime
the id never changes

#

use the id instead 👍

valid niche
#
@bot.command()
async def unban(ctx, user: discord.User):
  ban_entry = await ctx.guild.fetch_ban(user.id)
  await ctx.guild.unban(ban_entry.user)
#

now you want to work with a list of members to unban, so you'll have to work around that using commands.Greedy and a for loop

#

and probably also want a bit of error handling, in case the user is not banned

pliant gulch
#

This is kinda just useless, you can just pass the users ID to unban

slate swan
#

you can't mention the user

#

atleast it doesn't make sense

#

!d discord.User.mention

unkempt canyonBOT
#

property mention: str```
Returns a string that allows you to mention the given user.
slate swan
#

but it's gonna look like an id

valid niche
#

what is this supposed to be?

slate swan
#

discord thing

pliant gulch
valid niche
#

your client most likely doesn't have the user cached and it will not be a proper mention no

pliant gulch
#

Unless you want to ban someone before they even join the server

valid niche
pliant gulch
#

@valid niche You do a lot of PR reviews on disthon right?

valid niche
#

i mean i'm one of the contributors so it's one of my tasks yes

pliant gulch
#

If you have time would you mind taking a look at my most recent merge on my wrapper, the commands impl

valid niche
pliant gulch
#

Blanket is on vacation rn

slate swan
#

why

valid niche
#

...?

pliant gulch
valid niche
#

they were saying mention won't work properly because it will most likely just look like @glossy relic in your client

#

because the user won't be cached

pliant gulch
#

I just need someone to take a quick look at my string parser, my plugins metaclass and command client itself

slate swan
#

yes casually using eval so how i make allowed list

@bot.command()
async def math(ctx, *, expression:str):
  allowedlist = "1", "2", "3", "4", "5", "6", "7" ,"8", "9","0", "+", "*", "-", "/"
  if expression not in allowedlist:
    await ctx.reply("Invalid input.")
  else:
    calculation = eval(expression)
    await ctx.send('Math: {}\nAnswer: {}'.format(expression, calculation))```
#

ctrl+c > ctrl+v moment

placid skiff
#

You are checking if the string is in the list
You have instead to check if each words of the string are in the list

pliant gulch
#

This check would be so easy to bypass as you are using in

slate swan
#

so?

pliant gulch
#

Isn't there some kind of online API you can use for this

slate swan
#

solution?

pliant gulch
#

It would be safer then allowing eval on your local machine

slate swan
#

lmao no

#

i use replit cuz yes

valid niche
pliant gulch
#

to allow for from lefi.exts import ...

#

rather then from lefi import commands

valid niche
#

ah you want it to be an extra import like discord has

pliant gulch
#

as commands is an extension

slate swan
valid niche
slate swan
#

cuz as u said in is ez to bypass

pliant gulch
#

That is true but I'm sure you know what I mean

valid niche
#

because you weren't properly paying attention when i explained it

slate swan
#

make a loop

valid niche
#
@bot.command()
async def unban(ctx, user: discord.User):
  await ctx.guild.unban(user)
``` this is how you do a simple single user
slate swan
#

"while True:"...

pliant gulch
#

Thats just a useless API call

valid niche
pliant gulch
#

You can pass in an ID that isn't banned and it won't unban them

valid niche
#

there edited it

#

A simple single user unban

@bot.command()
async def unban(ctx, user: discord.User):
  await ctx.guild.unban(user)

If you want it to get multiple members, make your typehint like this

async def unban(ctx, users: commands.Greedy[discord.User])

And add a for loop to iterate over users and do the unbanning

#

@slate swan

placid skiff
valid niche
#

and check if there are any results

placid skiff
#

Well if he founds this complicated Imagine use regex lol

pliant gulch
#

For digits it would be easy, iirc (\+d)

#

And just use regex101 to carry

valid niche
#

r"(?![\d\+\-\/\*])"

#

then a findall and see if there's any result

pliant gulch
#

Wouldn't this be still be bypasable if you do smthg like os.remove("/");print("2+3")

#

You would need to actually validate afterwards

pliant gulch
#

You might be able to use ast.literal_eval actually, as that is very limited with what it can evaluate

#

!d ast.literal_eval

unkempt canyonBOT
#

ast.literal_eval(node_or_string)```
Safely evaluate an expression node or a string containing a Python literal or container display. The string or node provided may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, `None` and `Ellipsis`.

This can be used for safely evaluating strings containing Python values from untrusted sources without the need to parse the values oneself. It is not capable of evaluating arbitrarily complex expressions, for example involving operators or indexing.
pliant gulch
#

All you did was regex there

#

You still need to validate

valid niche
#
matches = re.findall(r"(?![\d\+\-\/\*])")
if matches:
  await ctx.send("Invalid input")
  return
pliant gulch
#

Yea, and it would find 2+3

valid niche
#

no

#

it's a (?!...) meaning it's inverted

pliant gulch
#

And your saying invalid inputs if it found a correct one?

valid niche
#

it matches anything that does NOT fit the regex

pliant gulch
#

Ah I see

#

Anyways, I think that would, and should be used in conjunction with ast.literal_eval

#

Still imo, not safe to do this at all and rather you should go online and search for a math eval API

valid niche
#

fair enough

slate swan
#

or just use buttons and make a button calculator 😂

hasty iron
valid niche
#

you know what, i want to try making a buttons calculator for the funs of it lmao

slate swan
#

you can have 5 buttons per row and 5 rows

#

25 buttons

#

plenty for a good calculator

valid niche
#

ah it was 5, thought it was 3

slate swan
#

¯_(ツ)_/¯

valid niche
#

remind me this weekend to make that calculator so that i actually have time or so

hasty iron
unkempt canyonBOT
#

discord/api/intents.py line 31

self.value = self.value + (1 << self.VALID_INTENTS[arg]) if kwargs[arg] else self.value```
valid niche
hasty iron
#

self.value |= flag value if the input is true else self.value &= ~flag value

valid niche
#

the VALID_INTENT is just the bit position and not the actual bit value

#

a members intent would be 000000000000010, but we have it stored as 1, since it's a bit shift of 1

hasty iron
pliant gulch
#

mmm the metaclass shit was clean there

#

me likey

valid niche
#

i assume that will work if you store your valid intents as the actual binary representation

#

we stored it as the bit shift

hasty iron
#

no i dont

#

for guilds intents for example its just 1 << 0

valid niche
#

wait let me just open your intents code i'll see

pliant gulch
#

I think flags is the only clean code blanket has PR'd for my wrapper

#

lmao

hasty iron
#

that’s not true

#

i made 90% of http and its clean

pliant gulch
#

👁️ 👄 👁️

valid niche
#

yeah you store all your intents as their binary representation

#

we store it as

    VALID_INTENTS: ClassVar[Dict[str, int]] = {
        'guilds': 0,
        'members': 1,
        'bans': 2,
        'emojis': 3,
        'integrations': 4,
        'webhooks': 5,
        'invites': 6,
        'voice': 7,
        'presence': 8,
        'message': 9,
        'reaction': 10,
        'typing': 11,
        'dm_message': 12,
        'dm_reaction': 13,
        'dm_typing': 14,
    }
slate swan
#

how to make square root aka ** ignore question2?

@bot.command()
async def math(ctx, question1:int, symbol:str, question2:int):
  if symbol == "+":
    embed = discord. Embed (title="Correct answer:", description=question1+question2, color=0x9208ea)
    await ctx.send(embed=embed)
  elif symbol == "-":
    embed = discord. Embed (title="Correct answer:", description=question1-question2, color=0x9208ea)
    await ctx.send(embed=embed)
  elif symbol == "*":
    embed = discord. Embed (title="Correct answer:", description=question1*question2, color=0x9208ea)
    await ctx.send(embed=embed)
  elif symbol == "/":
    embed = discord. Embed (title="Correct answer:", description=question1/question2, color=0x9208ea)
    await ctx.send(embed=embed)
  elif symbol == "**" and question1 == question2:
    square_root = question1 ** 0.5
    embed = discord.Embed (title="Correct answer:", description=square_root, color=0x9208ea)
    await ctx.send(embed=embed)```
valid niche
#

you store it as

guilds = 1
members = 2
bans = 4
emojis = 8
integrations = 16
``` etc.
hasty iron
#

well i just copied whatever was in the docs

valid niche
#

which is the binary representation, and that way you can do binary operations to flip individual bits

hasty iron
#

actually

#

isnt 1 << 0 just 1

#

so it doesn’t matter no?

valid niche
#

1 << 0 = 0001 = 1
1 << 1 = 0010 = 2
1 << 2 = 0100 = 4
1 << 3 = 1000 = 8
etc.

hasty iron
#

it should still work, the bitwise and and or

valid niche
#

since intents is just a long binary number where each bit is an intent

#

what you did is create the binary representation of the intent beforehand, we do it as the intents are made

#

so you store the actual binary representation of each intent, we just store the shift

#

yours is probably faster for cpu time, but less memory efficient. Our method is probably slower but more memory efficient. But it's so marginally small it doesn't matter in the context of python

#

it's literally a few cpu cycles/bytes of memory difference

hasty iron
#

am i missing something here or what, because 1 << 0 is just 1 which means bitwise operations can be done on 1

valid niche
#

you can do a bitwise operation on any integer

#

i can do a bitwise operation on 4 and 8

hasty iron
#

im getting confused at this point

valid niche
#

it will just convert these to 0100 and 1000 and then do the bitwise operation

#

!e

a = 4
b = 8
print(a | b)
``` will print 12
unkempt canyonBOT
#

@valid niche :white_check_mark: Your eval job has completed with return code 0.

12
hasty iron
#

oh i get it

#

it was my mistake

valid niche
#

a = 4 = 0100
b = 8 = 1000
a | b = 1100 = 12

hasty iron
#

i totally missed your point about how you store the intents

valid niche
#

yeah

#

we do the same, just in a different order

hasty iron
#

yeah i just got that now

valid niche
#

but the performance differences are so minimal, at only a few cpu cycles and a few bytes of memory, it matters nothing

#

if you were to do something similar in C, i wouldn't be surprised that the compiler would run so many optimizations it would turn out to be the same :p

pliant gulch
#

blanket write the C bindings for StringParser alr

#

I can't stand the 1 micro second it takes to parse tuple prefixes

hasty iron
#

what

#

i hate C

#

you write it

pliant gulch
#

fine

hasty iron
#

switch whole lib to cython rn

slate swan
#

Lmao

valid niche
hasty iron
#

no, i meant Cython

#

not CPython

pliant gulch
#

There exists cython and CPython

valid niche
#

ah i see

muted pier
#

I cant get my bot running

#

I cant figure it out

#

Pls help

valid niche
#

what happens when you run your code?

#

also share your code

muted pier
#

Sms

valid niche
#

wut?

valid niche
slate swan
muted pier
valid niche
muted pier
#

Yeah

#

But someone can steal my token

valid niche
#

and what stops me from stealing your token?

#

just remove the token from the code

muted pier
#

Ok

kindred epoch
#

bruh

muted pier
kindred epoch
#

?

muted pier
#

I hate mobile

valid niche
#

why are you programming on mobile?

muted pier
kindred epoch
#

ok lmao

muted pier
valid niche
#

because i've seen many people try it and they run into super weird errors due to how phones work. Also phones are just straight up annoying to work with and not a good development environment

muted pier
#

Ik

hasty iron
#

"but it works"

muted pier
#

but it works

hollow mortar
#

!e

unkempt canyonBOT
#
Command Help

!eval [code]
Can also use: e

*Run Python code and get the results.

This command supports multiple lines of code, including code wrapped inside a formatted code block. Code can be re-evaluated by editing the original message within 10 seconds and clicking the reaction that subsequently appears.

We've done our best to make this sandboxed, but do let us know if you manage to find an issue with it!*

hollow mortar
#

!e

x = 0
while x == 0:
  print("Hello world")
unkempt canyonBOT
#

@hollow mortar :x: Your eval job has completed with return code 143 (SIGTERM).

001 | Hello world
002 | Hello world
003 | Hello world
004 | Hello world
005 | Hello world
006 | Hello world
007 | Hello world
008 | Hello world
009 | Hello world
010 | Hello world
011 | Hello world
... (truncated - too many lines)

Full output: too long to upload

slate swan
#

.

#

Is there a way to give roles from 1 server in another server

#
@client.command(name = "server", aliases=["aliase"])
async def server(ctx):
    mainguild = client.get_guild(892718771242926132)
    staffguild = client.get_guild(900459740063207464)
    member = ctx.message.author
    var = discord.utils.get(staffguild.member.roles, id=900461033477533696)
    await member.add_roles(var)

#

wdym

dapper cobalt
#

!d discord.Guild.get_member

unkempt canyonBOT
toxic wharf
#

What should i change

slate swan
#

Everything

#

It's commands.Cog

toxic wharf
#

okay

slate swan
#

And it's add_cog(ClassName(bot))

#

And of course replace ClassName with your actual class name var

toxic wharf
#

im new lol

#

why are you laughing

#

Why this isn't work?

cloud dawn
slate swan
#

Copying code won't make you improve KryptonThink

torpid dew
#

Hi, I am trying to make a dictionary bot, why does this not work

import json
import requests
token = '*******'
app_id = "******"
app_key = "***************"
endpoint = "entries"
language_code = "en-gb"
word_id = input('What word would you like to search up in the Oxford Dictionary?\n')    
url = "https://od-api.oxforddictionaries.com/api/v2/" + endpoint + "/" + language_code + "/" + word_id.lower() + "?fields=definitions&strictMatch=false "
r = requests.get(url, headers={"app_id": app_id, "app_key": app_key})

if not r:
    print("that word doesn't exist lol")

else:
    print("text \n" + r.text)
    r = r.json()
    print("Definition:\n" + r.results[0].lexicalEntries[0].entries[0].senses[0].definitions[0])

client.run(TOKEN)
cloud dawn
cloud dawn
#

I recommend learning python first before going into discord bots

torpid dew
#

oh wait lol

slate swan
#

You can't just put python code and turn it into a bot like that CLk_KekW

torpid dew
#

i did print

torpid dew
cloud dawn
proud glade
#

i recommended going through the dpy docs

slate swan
#

You need to recode everything anyways

proud glade
#

^ what he said

#

LMAO

random sleet
#
async def on_raw_reaction_add(payload):
    guild = bot.get_guild(payload.guild_id) # Get guild
    member = get(guild.members, id=payload.user_id) # Get the member out of the guild
    # The channel ID should be an integer:
    if payload.channel_id == 870064115928948806: # Only channel where it will work
        if str(payload.emoji) == ":white_check_mark:": # Your emoji
            role = get(payload.member.guild.roles, id=869691107963990076) # Role ID
        else:
            role = get(guild.roles, name=payload.emoji)
        if role is not None: # If role exists
            await payload.member.add_roles(role)
            print(f"Added {role}")```

Can someone remake this to when the reaction has been canceled then the role will be removed 🙂
#

or help 🙂

kindred epoch
#

yes yes, this is the channel where we remake code lemon_hearteyes

random sleet
placid skiff
#

It's the same thing but you have to use delete_roles i think

kindred epoch
hasty iron
kindred epoch
slate swan
#

hello how can my bot when somone joins my discord server i want my bot to say Welcome to Python help!

hasty iron
#

!d discord.on_guild_join

unkempt canyonBOT
#

discord.on_guild_join(guild)```
Called when a [`Guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild "discord.Guild") is either created by the [`Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") or when the [`Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") joins a guild.

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

!d discord.on_member_join i think?

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.
brisk fiber
#

^

hasty iron
#

oh right

kindred epoch
#

lul

hasty iron
#

i thought he said when the bot joins

random sleet
slate swan
kindred epoch
hasty iron
kindred epoch
hasty iron
#

its an event

slate swan
kindred epoch
#

god

slate swan
#

ur not supposed to say "god" ur supposed to help me thats ur job

kindred epoch
#

do you know any basic python?

final iron
#

Nobody gets paid here

slate swan
hasty iron
#

damn got em, roasted

final iron
#

They're people volunteering

slate swan
hasty iron
#

its an event, you need to listen to it using Client.event or Bot.listen

kindred epoch
# slate swan i do

ok, well i dont think you do cuz you literally just said do i copy paste that

brave vessel
#

Hey everyone -- has anyone ever gotten an error about the event loop is not currently running? Trying to create views but I keep getting the same error

kindred epoch
#

ofc u were lemon_hearteyes

brave vessel
#

I don't know why discord isn't starting the event loop

hasty iron
#

classic move, "i was jk"

kindred epoch
brave vessel
#
sir-lancebot    |   File "/bot/bot/exts/events/trivianight/trivianight.py", line 19, in __init__
sir-lancebot    |     self.questions = Questions(self.scoreboard)
sir-lancebot    |   File "/bot/bot/exts/events/trivianight/_questions.py", line 97, in __init__
sir-lancebot    |     self.view = QuestionView()
sir-lancebot    |   File "/bot/bot/exts/events/trivianight/_questions.py", line 50, in __init__
sir-lancebot    |     super().__init__()
sir-lancebot    |   File "/usr/local/lib/python3.9/site-packages/discord/ui/view.py", line 166, in __init__
sir-lancebot    |     loop = asyncio.get_running_loop()
sir-lancebot    | RuntimeError: no running event loop
#

code for the snippet would just be


class QuestionView(View):
    """View for the questions."""

    def __init__(self):
        super().__init__()
        self.current_question = {}
        self.buttons = [QuestionButton(label) for label in ("A", "B", "C", "D")]
        for button in self.buttons:
            self.add_item(button)
hasty iron
#

the view is getting initialized outside a command?

brave vessel
#

yes, since I'm trying to set up a modular structure

hasty iron
#

well that won’t work

brave vessel
#

that doesn't? dpy has examples of it working outside a command

hasty iron
#

it doesn’t

#

all the examples have the views getting initialized inside a command

brave vessel
#

Ohh I see what yo're saying

#

Ah alright, I think I know how to fix it. Thanks

hasty iron
#

!d discord.Message.reference

unkempt canyonBOT
#

The message that this message references. This is only applicable to messages of type MessageType.pins_add, crossposted messages created by a followed channel integration, or message replies.

New in version 1.5.

pliant compass
#

I'm trying to get a users nickname from their user id. How would I do this?

valid niche
#

!d discord.Guild.get_member

unkempt canyonBOT
valid niche
#

!d discord.Member.nick

unkempt canyonBOT
pliant compass
valid niche
#

send me your code

pliant compass
#
for person in data["members"]:
        id = person["name"]
        name = guild.get_member(id)
valid niche
#

and how is guild defined?

pliant compass
#

This?
from discord import guild

valid niche
#

that's not correct

#

it would first of all be from discord import Guild, but that still wouldn't be correct

#

you never create the guild instance yourself, you always get it from some other source

#

for instance from ctx.guild, or client.get_guild(id), or from message.guild, or whatever you want

pliant compass
#

Ok.

valid niche
#

you need to specify WHAT guild you want

#

python doesn't magically know what you are referring to. It doesn't have telepathic powers. You need to explicitly state what you are referring to

#

in the case of a guild, you need to specify what guild

pliant compass
#

Thanks. I got it working.

royal zenith
#

i am going to cry

#

i have been trying to do this

#

for the last hour

#

error after error

valid niche
royal zenith
#

my friend who got it from github

valid niche
#

i hope you are aware that discord bots are generally a very tough topic, and not for the beginners. Whilst you can try going for it as a project, do know it will be a complete mess and it will be extremely difficult for you to get a basic grasp of what is going on

#

because it sounds like you are just starting out with python

valid niche
#

you said you copied code from github, but did you read their instructions on what you need to do? what is required to use it?

slate swan
#

if u ddint thats why there is error btw i add ur discord bot to my server it doesnt even have a perfix @royal zenith

royal zenith
#

its x

slate swan
#

oh

royal zenith
#

i dont want to put my bots token into a random config file

slate swan
slate swan
royal zenith
#

ik they normally are for the bot but still

valid niche
#

sounds like they have the understanding of the code, it might be better to ask them to properly set it up as they can see the code and knows what needs to be done

slate swan
royal zenith
#

they dont know what to do neither do i

valid niche
#

i mean idk what the code is, i haven't seen any of your code, i've only seen the error and you frantically trying to pip install with what seems to be no knowledge on python

#

most here can help you with specific questions, but they cannot help you get all knowledge from the ground up, that takes a long while

pliant gulch
#

utils.json_loader seems like a local module

#

Perhaps you didn't clone the repo properly

valid niche
#

utils is either a local module, or part of a bigger module yes

royal zenith
#

its kinda annoying me

slate swan
slate swan
#

bc i have smart devlopers that been coding for python for 7 years!

valid niche
#

okay let me put it this way: You seem to be frantically trying things that you aren't sure about, you said you've been trying for hours. Have you read the instructions that the github page gives if there are any?

royal zenith
#

my friend gave me the code

royal zenith
#

because i like the bot

slate swan
#

dw i got em

valid perch
#

Have you gotten all the files?

slate swan
#

syskey hit dms breh, alrdy said i would help u

slate swan
#

he has everything he needs

royal zenith
#

no shit aint workign tho

slate swan
#

local import

valid perch
#

Righto, otherwise go yoink it from github

slate swan
royal zenith
#

yep

#

i copied the folder innit

hasty iron
#

why not just put it in github

#

and let him clone it?

slate swan
royal zenith
slate swan
royal zenith
#

idk

hasty iron
#

damn

valid niche
slate swan
#

dude if u just copy somone random code its gonna give u a random error

royal zenith
#

i copied all the code it needed, and all the files

valid perch
#

It's also possible you'll want a __init__.py in the utils folder, tis something that occurs with our utils folder sometime

slate swan
slate swan
valid niche
slate swan
#

!d help bot

unkempt canyonBOT
#

help([object])```
Invoke the built-in help system. (This function is intended for interactive use.) If no argument is given, the interactive help system starts on the interpreter console. If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. If the argument is any other kind of object, a help page on the object is generated.

Note that if a slash(/) appears in the parameter list of a function when invoking [`help()`](https://docs.python.org/3/library/functions.html#help "help"), it means that the parameters prior to the slash are positional-only. For more info, see [the FAQ entry on positional-only parameters](https://docs.python.org/3/faq/programming.html#faq-positional-only-arguments).

This function is added to the built-in namespace by the [`site`](https://docs.python.org/3/library/site.html#module-site "site: Module responsible for site-specific configuration.") module.
valid niche
royal zenith
#

i posted everything there

valid niche
#

you can see what it imports at the top, and see if you can work from there, keep in mind that in a lot of cases the import name and the pip install name can be different

slate swan
#

can anyone tell me how to make a verifcation command for my discord bot and if u do pls send me the code

valid niche
#

define "verification bot"

#

what does it need to verify?

#

also spoonfeeding generally isn't done here

slate swan
#

like

#

for example

valid niche
#

those are generally made that when you complete the action, it gives a role, and all channels are set to private unless you have that role

slate swan
#

i do have the role

valid niche
#

i do have to say: those systems are very dated and not used anymore. It repels most users and doesn't help in any way

slate swan
#

oh

valid niche
#

it doesn't help against spammers, it doesn't help against self bots, it doesn't help against raids

slate swan
#

oh

valid niche
#

i mean you can still make it, but i speak from experience, these systems don't really work well

#

it just makes users like "why do i have to take all these extra steps, i just want to join the server"

pliant gulch
#

Just use a Captcha module if you really want something secure

#

Unless those selfbots have an OCR it won't be able to bypass

valid niche
#

wickbot is for instance a bot that does proper protection using a captcha

stable delta
#

for await asyncio.sleep(x), does it cancel when the code stops?

#

like if you reload the code

valid niche
#

oh and most of those security bots are closed source, otherwise attackers will look at the code and find the weak points/workarounds

valid niche
#

sleep is your code still running, just not doing anything

distant warren
#

need some help, anyone there

valid perch
#

Lots of people

valid niche
hasty iron
#

don’t get fooled, nobody is here

slate swan
#

euhJHW

valid niche
#

but @slate swan for anything like security or verification, anything that does a proper job is closed source and you'll need to find your own solution

stable delta
valid perch
#

persist that data

stable delta
valid niche
#

you store either the startdate and a duration, or you store the enddate, then regularly check if it expired and undo the infraction

slate swan
#

**@commands.command(name="lock") @commands.has_permissions(manage_channels=True) async def lock(self, ctx, channel : discord.TextChannel=None): overwrite = ctx.channel.overwrites_for(ctx.guild.default_role) overwrite.send_messages = False await ctx.channel.set_permissions(ctx.guild.default_role, overwrite=overwrite) await ctx.send('Channel locked.')**

#

if u want a lock command

stable delta
valid niche
#

yes

#

i use it for my tempmutes/tempbans

stable delta
#

sick

slate swan
#

who wants a mute command?

#

i mean who wants a mute code

pliant gulch
#

If your gonna use a database really suggest an SQL one

#

the language is amazing for this type of stuff

#

makes it easy to do mutes

stable delta
slate swan
#

~~***@commands.command(name="mute", description="Mutes the specified user.") @commands.has_permissions(manage_messages=True) async def mute(self, ctx, member: discord.Member, *, reason=None): guild = ctx.guild mutedRole = discord.utils.get(guild.roles, name="Muted")~~***

boreal ravine
#

@slate swan why spoonfeed

#

wtf

valid perch
#

I mean, it doesn't mute anyone haha

slate swan
valid perch
#

lmao

pliant gulch
#

mostly from anand sql guy

stable delta
#

aight I'll check it out later

#

ty

slate swan
#

@shrewd pasture evil guy

shrewd pasture
#

indeed

slate swan
#

Is it possible to grab a discord.User object of a member that has no contact with the bot? Like if they aren't in any of the servers the bot is in?

#

Just curious

slate swan
slate swan
shrewd pasture
#

quick question for you guys. Been stuck on this
I need to run through every member in a guild and check if the member is in the other guild. Here is the current code:

  @commands.command()
  async def run(self, ctx):
    role = discord.utils.get(ctx.guild.roles, name="Owners / Managers")

    if role is None:
            # Doesn't exist, create the role here
      role = await ctx.guild.create_role(name="Owners / Managers")
    ocm = self.bot.get_guild(891928045236154388)
    x = ctx.guild.members
    for member in x:
      print(f"{member} has been confirmed in {x}")
      guild = self.bot.get_guild(ocm)
      check = int(member.id)
      if guild.get_member(check) is not None: #error here i added check thinking it needed to be an id and int
        await self.bot.add_roles(member, role)
      else:
        return;

Error:
if guild.get_member(check) is not None:
AttributeError: 'NoneType' object has no attribute 'get_member'

slate swan
#

no idea

#

@commands.command(name="mute", description="Mutes the specified user.")
@commands.has_permissions(manage_messages=True)
async def mute(self, ctx, member: discord.Member, *, reason=None):
guild = ctx.guild
mutedRole = discord.utils.get(guild.roles, name="Muted")

slate swan
#

`~~***@commands.command()
async def run(self, ctx):
role = discord.utils.get(ctx.guild.roles, name="Owners / Managers")

if role is None:
        # Doesn't exist, create the role here
  role = await ctx.guild.create_role(name="Owners / Managers")
ocm = self.bot.get_guild(891928045236154388)
x = ctx.guild.members
for member in x:
  print(f"{member} has been confirmed in {x}")
  guild = self.bot.get_guild(ocm)
  check = int(member.id)
  if guild.get_member(check) is not None: #error here i added check thinking it needed to be an id and int
    await self.bot.add_roles(member, role)
  else:
    return;`~~***
slate swan
#

wait no i might be stupid

shrewd pasture
slate swan
#

dont listen to my advice lmao

shrewd pasture
#

dont think so though

pliant gulch
boreal ravine
shrewd pasture
boreal ravine
#

🗿

slate swan
#

ez

valid perch
#

!d discord.Client.get_user

unkempt canyonBOT
pliant gulch
#

!d discord.Guild.get_member

unkempt canyonBOT
slate swan
#

oh get_user

#

wait huh

shrewd pasture
slate swan
#

oh so i was right

#

oh and wrong at the same time

boreal ravine
#

Maybe fetch the guild/member instead of getting it

slate swan
#

well he prob has his reason for why its not using guild obv

#

like for instance, if its a paramter that want's an ID or smth

pliant gulch
#

get_guild would return the Guild obj

#

The part I really see wrong about this code is the self.bot.add_roles

#

Since the rewrite that has been changed to Member.add_roles

slate swan
pliant gulch
#

which was about like 6 years ago iirc

pliant gulch
slate swan
#

ohh ok

#

okok yeah u right

#

i'd just do client.get_guild, guild.get_member

pliant gulch
#

Which is what they are doing

slate swan
#

i thought they were doing client.get_user?

shrewd pasture
#

why would i do that

#

when im attempting to fetch the check of a user in a server or not

pliant gulch
# shrewd pasture no clue

Actually, ocm is already assigned as get_guild is there any reason why you are passing a Guild obj to get_guild again?

shrewd pasture
#

i see

slate swan
#

oh i thoguht u were using self.bot to get the member @shrewd pasture

#

mb thats on me

#

im blind i should read better

pliant gulch
shrewd pasture
#

yes

pliant gulch
#

Then change self.bot.add_roles

shrewd pasture
#

let me test

pliant gulch
#

to Member.add_roles

#

As that was pre-rewrite, aka old code

shrewd pasture
#

why would i write that

slate swan
#

its o l d c o d e

pliant gulch
#

Because bot.add_roles doesn't exist

shrewd pasture
#

im getting the bot

#

oh

#

why would i get Member to set the role

slate swan
shrewd pasture
#

im not sure i understand

pliant gulch
#

Are you trying to give the bot a role?

shrewd pasture
#

no

pliant gulch
#

Ok, so its Member.add_roles

slate swan
#

if it was the bot u'd use bot.user btw

pliant gulch
#

member being the Member instance

#

corresponding to the guild

hasty iron
slate swan
pliant gulch
hasty iron
unkempt canyonBOT
#

property me: discord.member.Member```
Similar to [`Client.user`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client.user "discord.Client.user") except an instance of [`Member`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member "discord.Member"). This is essentially used to get the member version of yourself.
slate swan
#

wait w u t

shrewd pasture
#

got the error unfdefined name Member

slate swan
#

ohhh wait nvm i get it now

boreal ravine
pliant gulch
hasty iron
#

being the bot

shrewd pasture
#

theres no member instance in my code

boreal ravine
#

same thing then

hasty iron
slate swan
#
Traceback (most recent call last):
  File "main.py", line 100, in <module>
    bot.load_extension(f'cogs.{filename[:-3]}')
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 678, in load_extension
    self._load_from_module_spec(spec, name)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 615, in _load_from_module_spec
    raise errors.NoEntryPointError(key)
discord.ext.commands.errors.NoEntryPointError: Extension 'cogs.giveaway' has no 'setup' function.```
pliant gulch
#

see the part where you did guild.get_member

#

Change that to ocm.get_member pass the ID of the member, and assign this to a variable

slate swan
pliant gulch
#

check if it isn't None, then use add_roles

boreal ravine
slate swan
#

I know its something like this: py def setup(bot): bot.add_cog(Cog(bot))

#

I didnt make it a cog tho

slate swan
#

what do I name it??

shrewd pasture
#

how do i add the Member instance

slate swan
#

my file name is giveaway.py

shrewd pasture
#

kinda slow right now

boreal ravine
slate swan
#

I did make it a class lol

pliant gulch
#

get_member will return the Member instance if its found

boreal ravine
shrewd pasture
slate swan
#

I mean I didnt make a class

#

must I??

boreal ravine
shrewd pasture
#
try:
  check = ocm.get_member(member.id)
except:
  return
pliant gulch
slate swan
#

nevermind i gtg

pliant gulch
#

try-except won't work as this won't raise an error

boreal ravine
shrewd pasture
#

still undefined name member

#

after

pliant gulch
#

Show your code

shrewd pasture
#

check = ocm.get_member(member.id)
if check:
await Member.add_roles(member, role)
else:
return;

hasty iron
#

man that’s basic python

#

or atleast knowledge you need for dpy

shrewd pasture
#
  @commands.command()
  async def run(self, ctx):
    role = discord.utils.get(ctx.guild.roles, name="Owners / Managers")

    if role is None:
            # Doesn't exist, create the role here
      role = await ctx.guild.create_role(name="Owners / Managers")
    ocm = self.bot.get_guild(891928045236154388)
    x = ctx.guild.members
    for member in x:
      print(f"{member} has been confirmed in {x}")
      check = ocm.get_member(member.id)
      if check:
        await Member.add_roles(member, role)
      else:
        return;
pliant gulch
#

Member???

hasty iron
#

im self taught too, your point doesn’t make sense

pliant gulch
#

Your Member isn't is assigned to check

#

you do check.add_roles and you don't pass member to this

slate swan
#

isnt everyone here self taught lol?

pliant gulch
#

You only pass role

slate swan
#

like huh

pliant gulch
#

@hasty iron are we gonna do stubs

hasty iron
#

uh

magic ore
#

type stubs?

hasty iron
#

we can but idk

pliant gulch
#

I feel like if we added stubs we would get clowned on

#

all just for overloads smh

hasty iron
#

just add overloads to the files? no need for stubs

magic ore
#

there are already dpy type stubs for 1.7.x by bryanforbes

pliant gulch
#

that takes up to much space blanket

hasty iron
#

who cares

pliant gulch
magic ore
#

ah

hasty iron
#

it looks nice too

#

easy

pliant gulch
#

If you stub one file you gotta stub the rest

shrewd pasture
#

@pliant gulch it just gave me a Missing Access error

hasty iron
#

that’s pain

shrewd pasture
#

but it has administrator

#

should i use try for that?

#

i am so lost

pliant gulch
shrewd pasture
#

yes

hasty iron
#

i can do stubgen but it’s not the best, ill have to do some changes to the generated stubs

pliant gulch
#

Ok sure I would use a try-except here

shrewd pasture
#

its supposed to be shuffling through all members

pliant gulch
#

As this is a hierarchy issue

shrewd pasture
#

in 1 servers

#

and checking if its in another

#

wait it might be giving it in the wrong server

pliant gulch
#

top_role iirc, but imo its a lot easier just to try-except for missing access

#

!d discord.Member.top_role

unkempt canyonBOT
#

property top_role: Role```
Returns the member’s highest role.

This is useful for figuring where a member stands in the role hierarchy chain.
shrewd pasture
#

its giving the role in ocm and not the ctx.guild

#

how would i fix that cause i tried just doing ctx.guild instead of Member and it gave an error

pliant gulch
#

So you want to assign the roles in ctx.guild?

shrewd pasture
#

yes

pliant gulch
#

do member then

shrewd pasture
#

i just dont know how to fix it

pliant gulch
#

As you iterate through ctx.guild.members

shrewd pasture
#

ohh

#

gotcha

#

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Guild' object has no attribute 'member'

#

members?

#

oh im dumb

#

lemme try this

#

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'list' object has no attribute 'add_roles'

pliant gulch
#

Don't do ctx.guild.member

shrewd pasture
#

gave that error

pliant gulch
#

You already ARE ITERATING over ctx.guild.members

#

for member in ctx.guild.members:

#

member is the Member instance

lost lagoon
#

how do i make sure that only one person is answering

#

i was testing and came across the problem of multiple tests running at once and more than one person answering

shrewd pasture
#

@pliant gulch kinda worked?
it spamed the fuck out of my console though

  @commands.command()
  async def run(self, ctx):
    role = discord.utils.get(ctx.guild.roles, name="Owners / Managers")

    if role is None:
            # Doesn't exist, create the role here
      role = await ctx.guild.create_role(name="Owners / Managers")
    ocm = self.bot.get_guild(891928045236154388)
    x = ctx.guild.members
    for member in x:
      Member = ocm.get_member(member.id)
      for member in ctx.guild.members:
        member.add_roles(role)
        print(f"{member} has been confirmed in {ctx.guild}")
#

like every member was in console

#

i dont know why the check didnt work

pliant gulch
shrewd pasture
#

is it supposed to be if

lusty swallow
lost lagoon
#

ok

pliant gulch
unkempt canyonBOT
#

property mutual_guilds: List[Guild]```
The guilds that the user shares with the client.

Note

This will only return mutual guilds within the client’s internal cache.

New in version 1.7.
shrewd pasture
#

bro

#

i didnt know that existed i swear

pliant gulch
#

This returns a list of Guild objects,

lost lagoon
pliant gulch
#

you check if ocm is inside of this list

#

if so add the role

lusty swallow
shrewd pasture
#

can u quickly give an example if you dont mind

#

im so tired and its been 5 hours of working on this

lost lagoon
lusty swallow
pliant gulch
lost lagoon
#

how do i write that

shrewd pasture
pliant gulch
#

!e ```py
guild = 1
guilds = [1, 2]

if guild in guilds:
print("yes its in")

unkempt canyonBOT
#

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

yes its in
lusty swallow
pliant gulch
#

guilds here being the list from mutual_guilds

#

guild being ocm

shrewd pasture
lost lagoon
lusty swallow
lost lagoon
#

yes

lusty swallow
#

you might also be needing to use either self or global

shrewd pasture
pliant gulch
#

as somehow you are getting bot.user

shrewd pasture
# pliant gulch Can you show your code
  @commands.command()
  async def run(self, ctx):
    role = discord.utils.get(ctx.guild.roles, name="Owners / Managers")

    if role is None:
            # Doesn't exist, create the role here
      role = await ctx.guild.create_role(name="Owners / Managers")
    ocm = self.bot.get_guild(891928045236154388)
    guilds = [891928045236154388, 2]
    x = ctx.guild.members
    for member in x:
      for member in member.mutual_guilds:
        if member.mutual_guilds in guilds:
            member.add_roles(role)
pliant gulch
pliant gulch
shrewd pasture
#

oh

pliant gulch
#

You check if ocm is in mutual_guilds

#

And somehow here, somewhere in the loop you are getting the bots user

#

You don't iterate through mutual guilds at all, and esp not for member

shrewd pasture
#

this is it now:

pliant gulch
#

You simply, after for member in x: check if ocm is in mutual_guilds of the member

shrewd pasture
#
  @commands.command()
  async def run(self, ctx):
    role = discord.utils.get(ctx.guild.roles, name="Owners / Managers")

    if role is None:
            # Doesn't exist, create the role here
      role = await ctx.guild.create_role(name="Owners / Managers")
    ocm = self.bot.get_guild(891928045236154388)
    x = ctx.guild.members
    for member in x:
      for member in member.mutual_guilds:
        if ocm in member.mutual_guilds:
            member.add_roles(role)
pliant gulch
#

then add the roles to member

shrewd pasture
#

ohh

pliant gulch
#

Don't iterate member.mutual_guilds

#

Just delete that part, and use if ocm in member.mutual_guilds

shrewd pasture
#

same error

#

this line
if ocm in member.mutual_guilds:

#
  @commands.command()
  async def run(self, ctx):
    role = discord.utils.get(ctx.guild.roles, name="Owners / Managers")

    if role is None:
            # Doesn't exist, create the role here
      role = await ctx.guild.create_role(name="Owners / Managers")
    ocm = self.bot.get_guild(891928045236154388)
    x = ctx.guild.members
    for member in x:
        if ocm in member.mutual_guilds:
            member.add_roles(role)
pliant gulch
#

Dedent it

#

Your one indentation level off

shrewd pasture
#

same error

pliant gulch
#

Error is clientuser add_roles?

shrewd pasture
#

no mutual_guilds

pliant gulch
#

Ah, clientuser has no attr mutual_guilds

#

Idk why you are getting the bots client user makes no sense to me

#

Try checking if the member is not the bot's client user

#

if member is self.bot.user: continue

shrewd pasture
#

with that line

#

it doesnt even run the code

#
  @commands.command()
  async def run(self, ctx):
    role = discord.utils.get(ctx.guild.roles, name="Owners / Managers")

    if role is None:
            # Doesn't exist, create the role here
      role = await ctx.guild.create_role(name="Owners / Managers")
    ocm = self.bot.get_guild(891928045236154388)
    x = ctx.guild.members
    for member in x:
      if member is self.bot.user:
        print("dummy")
        if ocm in member.mutual_guilds:
          member.add_roles(role)
pliant gulch
#

It doens't print dummy?

shrewd pasture
#

no

#

its looping

#

thats for sure

pliant gulch
#

OK just do ```py
for member in ctx.guild.members:
if isinstance(member, discord.ClientUser):
continue

if ocm in member.mutual_guilds:
    await member.add_roles(role)
#

Replace the bottom part with this

shrewd pasture
#
  File "/home/runner/Zyfe-Reps/cogs/connect_handlerv2.py", line 33, in run
    if ocm in member.mutual_guilds:
AttributeError: 'ClientUser' object has no attribute 'mutual_guilds'
#

@pliant gulch

pliant gulch
#

Show your code now that you replaced it

shrewd pasture
#
  @commands.command()
  async def run(self, ctx):
    role = discord.utils.get(ctx.guild.roles, name="Owners / Managers")

    if role is None:
            # Doesn't exist, create the role here
      role = await ctx.guild.create_role(name="Owners / Managers")
    ocm = self.bot.get_guild(891928045236154388)
    for member in ctx.guild.members:
        if isinstance(member, discord.ClientUser):
            continue

        if ocm in member.mutual_guilds:
            await member.add_roles(role)
pliant gulch
#

Ok, so for some reason the clientuser is passing the isinstance which should be continuing the loop so it doesn't add its roles

#

And in the first place I am absolutely confused as to why members contains a user in there

#

Do you have member intents and everything?

shrewd pasture
#

yes thats added

pliant gulch
#

Can you print ctx.guild.members

shrewd pasture
#

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

bot = commands.Bot(command_prefix='!', intents=intents, owner_id=348694166710124547)
client = bot

shrewd pasture
#
<Member id=815379168644300891 name='hiro035' discriminator='8033' bot=False nick=None guild=<Guild id=897214863342981121 name='Sypher | DOOM' shard_id=None chunked=True member_count=616>>, <Member id=545423545774112788 name='zerok1' discriminator='4539' bot=False nick=None guild=<Guild id=897214863342981121 name='Sypher | DOOM' shard_id=None chunked=True member_count=616>>, <Member id=169610583883251713 name='>Alam' discriminator='0001' bot=False nick=None guild=<Guild id=897214863342981121 name='Sypher | DOOM' shard_id=None chunked=True member_count=616>>, <Member id=884515295375552563 name='syn' discriminator='0562' bot=False nick=None guild=<Guild id=897214863342981121 name='Sypher | DOOM' shard_id=None chunked=True member_count=616>>]
#

maybe thats why?

#

wait

#

idek anymore

#

im so lost

pliant gulch
#

Still confused as why somehow self.bot.user is in this list

shrewd pasture
#

agreed

pliant gulch
#

Maybe swap out the isinstance with, if member is self.bot.user

#

And actually can you print self.bot.user as well?

shrewd pasture
#

Zyfe#2912

#

@pliant gulch

pliant gulch
#

Can you show the terminal of the print

#

Or is it just that

shrewd pasture
#

thats it

#
Zyfe#2912
Ignoring exception in command run:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/runner/Zyfe-Reps/cogs/connect_handlerv2.py", line 34, in run
    if ocm in member.mutual_guilds:
AttributeError: 'ClientUser' object has no attribute 'mutual_guilds'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'ClientUser' object has no attribute 'mutual_guilds'
boreal ravine
shrewd pasture
#

then it hits the error statement

hasty iron
#

removed?

#

!d discord.User.mutual_guilds

unkempt canyonBOT
#

property mutual_guilds: List[Guild]```
The guilds that the user shares with the client.

Note

This will only return mutual guilds within the client’s internal cache.

New in version 1.7.
boreal ravine
#

hm

hasty iron
#

doesn’t seem removed to me

pliant gulch
#

As I have no clue why a client user is inside a list of members

#

At this point just suppress it via try except

shrewd pasture
#
  @commands.command()
  async def run(self, ctx):
    role = discord.utils.get(ctx.guild.roles, name="Owners / Managers")

    if role is None:
            # Doesn't exist, create the role here
      role = await ctx.guild.create_role(name="Owners / Managers")
    ocm = self.bot.get_guild(891928045236154388)
    for member in ctx.guild.members:
        if isinstance(member, discord.ClientUser):
            continue
        try:
          if ocm in member.mutual_guilds:
              await member.add_roles(role)
        except:
          print("fuck")
#

@pliant gulch

#

it printed "fuck" once

#

WAIT

pliant gulch
#

And did it add roles ?

shrewd pasture
#

it worked

pliant gulch
#

Ok nice

shrewd pasture
#

oh my god

pliant gulch
#

The try except is only there to shut up the client user error

#

Cus idk why a client user is in a list of members

shrewd pasture
#

dms for a moment?

#

if you dont mind

pliant gulch
#

You can even just remove the print and let it pass

#

My dms are off

shrewd pasture
#

mind adding me for just a minute

slate swan
#

anybody has a idea for a command?im out of ideas

shrewd pasture
rain olive
#

a command

#

singular

slate swan
shrewd pasture
slate swan
shrewd pasture
#

its fun but takes time

#

i made it took a little while to make it perfect

slate swan
#

yeah'

lusty swallow
shrewd pasture
#

Dont forget to make anti spam in it

rain olive
#

number guessing game @slate swan

lusty swallow
#

i meant that as a question

slate swan
#

oh

slate swan
kindred epoch
#

Number guessing game what

lusty swallow
rain olive
#

use wait_for

rain olive
slate swan
#

ill do learderboard and the number guessing game thanks allot

boreal ravine
slate swan
stark hearth
#
    @commands.command(name = 'userinfo', help = 'Shows discord info about user', aliases=["whois"])
    async def userinfo(self, ctx, member: discord.Member = None):

        if member == None:
            member = ctx.author

        roles = [role for role in member.roles][1:]

        em = discord.Embed(
            description = f'**User Infomation - **{member.mention}',
            colour=member.color, 
            timestamp=ctx.message.created_at
            )

        em.set_thumbnail(url = member.avatar_url)
        em.set_footer(text=f'Requested by {ctx.author}', icon_url=ctx.author.avatar_url)

        em.add_field(name='ID:', value=f'`{member.id}`')
        em.add_field(name='Nickname:', value=member.display_name)

        em.add_field(name='Created at:', value=member.created_at.astimezone(timezone('US/Pacific'))
        em.add_field(name='Joined at:', value=member.joined_at.astimezone(timezone('US/Pacific'))

        em.add_field(name=f'Roles ({len(roles)})', value="\n".join([role.mention for role in roles]))
        em.add_field(name='Top Role:', value=member.top_role.mention)

        em.add_field(name = 'Bot:', value = member.bot)

        await ctx.send(embed=embed)

its saying that i have an syntax error at em.add_field(name='Joined at:', value=member.joined_at.astimezone(timezone('US/Pacific')). why is that

hasty iron
#

missing )

brave vessel
stark hearth
brave vessel
#

Np

stark hearth
#

wait

#

its still not working

#

this seems so easy, yet im just too blind

#

wait

hasty iron
#

its the same error

stark hearth
#

im blind got it

stark hearth
slate swan
#

How can I run

@bot.command()

And

@bot.event

And both should still work?

supple thorn
#

How can you count the overall seconds of datetime.now().timestamp() - a datetime.now().timestamp() i did earlier

#

It restarts at 60 which makes sense

#

I need to check if it reaches a certain number to unmute someone

#

And its higher than 59

errant shuttle
#

Hey, i am trying to make a muted role when a command is given but it is saying self is not defined. and when I don't give self, it says missing argument "self"
Here is my code

if found_muted_role == True:
        await ctx.reply("I found a muted role!")
    else:
        await ctx.send("I didn't find any mute role so I am creating one!")
        await Guild.create_role(self,
            name = "Muted",
            permissions = Permissions.none,
            hoist = True,
            mentionable = True,
            reason = "A user tried to mute someone!"
        )
        await ctx.send("I have created the muted role")
errant shuttle
#

@slate swan ```
Ignoring exception in command mute:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/ext/commands/core.py", line 168, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 112, in mute
await Guild.create_role(self,
NameError: name 'self' is not defined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/ext/commands/bot.py", line 995, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/ext/commands/core.py", line 895, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/ext/commands/core.py", line 177, in wrapped
raise CommandInvokeError(exc) from exc
nextcord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'self' is not defined

slate swan
errant shuttle
#

also it is saying File "main.py", line 112, in mute await Guild.create_role(self, NameError: name 'self' is not defined

slate swan
#

this ^^

errant shuttle
#

ye

#

so what shud i do?

slate swan
#

try to remove?

#

and test commanda gain?

slate swan
errant shuttle
slate swan
#

the code that u just sent, is in cogs or in main file?

slate swan
#

bruh

#

there is no self thing in main

errant shuttle
#

so imma just switch to cogs

slate swan
#

alright

slate swan
#

anyone help

#

HELP

supple thorn
#

Read the error @slate swan

slate swan
#

i did i jut dont understand can u send me the real code and ill copy paste it

supple thorn
valid galleon
#

is it a good idea to move all my helper functions into a seperate cog and then import them into the other cogs?

slate swan
supple thorn
#

Second of all please learn basic python before diving into creating discord bots

slate swan
#

go show off

valid galleon
supple thorn
#

And judging by your file name

#

Thats not in a cog

slate swan
valid galleon
craggy shuttle
#

can you suggest me a python discord library ?

valid galleon
#

or should i keep them in the specific cog?

boreal ravine
valid galleon
craggy shuttle
#

thanks I will go with pycord

boreal ravine
#

I recommend disnake

#

but you do you

valid galleon
#

pycord is early in development so there are a lot of bugs in it

#

i think disnake is more stable atm

craggy shuttle
#

I have used discord.py previously and pycord is pretty much the same

valid galleon
#

i think disnake is the same too

#

i havent used it so idk

lusty swallow
#

disnake is literally the same as dpy. i advice you use that for temporary stuff until pycord or libs you want is stable

#

you can literally just replace the word discord with disnake and it would still work

#

the only difference is with interaction as most forks are

slate swan
#

I can't say I recommend pycord at all tbh

#

Over disnake

slate swan
lusty swallow
#

same. i only used disnake because hunter recommended it to me and it's almost as if there wasn't any changes

slate swan
#

Disnake implemented slashes in the best way possible and usually adds stable features before any other lib or fork

#

¯\_(ツ)_/¯

errant shuttle
# slate swan alright

Hey I am getting this error

Ignoring exception in command mute:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/ext/commands/core.py", line 168, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/runner/Efendo-Bot-SRC/modules/mod/cog.py", line 114, in mute
    await Guild.create_role(self,
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/guild.py", line 2495, in create_role
    fields['permissions'] = str(permissions.value)
AttributeError: 'function' object has no attribute 'value'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
``` on this code
```py
if found_muted_role == True:
                await ctx.reply("I found a muted role!")
            else:
                await ctx.send("I didn't find any mute role so I am creating one!")
                await Guild.create_role(self,
                    name = "Muted",
                    permissions = Permissions.none,
                    hoist = True,
                    mentionable = True,
                    reason = "A user tried to mute someone!"
                )
                await ctx.send("I have created the muted role")

There is something wrong with the permss

slate swan
#

You need a guild instance not the class

errant shuttle
slate swan
#

Please learn basic OOP

#

And replace Guild with ctx.guild

errant shuttle
#

ok :\

#

oooooooooooooohhhh i forgot

slate swan
#

Also self isn't a param so remove that too

slate swan
boreal ravine
#

he's literally stating facts

#

your supposed to learn python first not make a bot then learn python

valid galleon
#

some people man...

slate swan
valid galleon
boreal ravine
valid galleon
#

you can have multiple commands and events in the same file

boreal ravine
#

is there an error?

supple thorn
slate swan
#

Like

#

@bot.command()
async def stuffHere(ctx):
Djduejjfsi

@bot.event
async def jxis(ctx):
Difnieend

#

Only the @bot.command() works

boreal ravine
#

yes

slate swan
valid galleon
slate swan
#

An asshole like you should be ignored 😂

boreal ravine
slate swan
#

Oh

#

I'm new to this

#

Bye lemme go learn

valid galleon
#

is it for a temp mute command?

slate swan
#

For a datetime object

supple thorn
#

Its a fight command that mutes the loser between 1-120 seconds

slate swan
#

Ok nvm there isn't

supple thorn
slate swan
supple thorn
#

Why would i need to add 120 seconds

valid galleon
#

so its similar to the normal mute command, you just have to include a time conversion thing like this and then at the end do asyncio.sleep(tempmute)
time convert will look like this:

        time_convert = {"s":1, "m":60, "h":3600,"d":86400}
        tempmute = int(time[0]) * time_convert[time[-1]]```
slate swan
#

Oh right

valid galleon
#

then after the sleep, remove the role

supple thorn
#

I do regret using asyncio.sleep for unmuting rather than learning how to use tasks back then

supple thorn
valid galleon
#

its better to use it, actually. harder method would be using a db, and storing the time info there and then unmuting

supple thorn
#

Im using tasks that pretty much counts the seconds between the timestamp of when they were muted and the timestamp rn

supple thorn
#

Using mongodb to store data

valid galleon
#

i havent used tasks so idrk

slate swan
supple thorn
#

Yeah that is actually my problem

#

So im forcing my way to fix it

valid galleon
slate swan
#

¯\_(ツ)_/¯

supple thorn
#

I just dont know how to make it count further than 59

#

It goes back to 0

#

I can just make it

#

Subtract 1 every second on the mute time

#

And check if its 0

#

If so

#

Unmute them

#

That would work right?

#

New problem

#

How do i check if they are the same user in the same guild

slate swan
#

Save the guild he was muted it and check if he's in that guild

valid galleon
#

so uhh i made the afk command, but theres a problem:

#

it immediately removes the afk when the command is run

slate swan
#

hello i need help abt discord flags ( badges)

#

i already know that premium_type is nitro but for hypesquad houses idk

valid galleon
#

idt there is one for that

slate swan
#

@valid galleonah :(

#

so i wanna fetch user badges but for houses i dont know their thing

boreal ravine
unkempt canyonBOT
#

property public_flags```
Equivalent to [`User.public_flags`](https://discordpy.readthedocs.io/en/master/api.html#discord.User.public_flags "discord.User.public_flags")
slate swan
#

thx gonna check it

dapper cobalt
dim cedar
#

hello

#

need help

boreal ravine
dim cedar
#
import googletrans
from googletrans import Translator

translator= Translator()
translation = translator.translate("hi", dest= "bn")
print(translation.text)```
dapper cobalt
dim cedar
#

just googletrans

dapper cobalt
#

Move to google trans new since this one is outdated.

slate swan
#

@boreal ravinedoes it work when sent via webhook ?

dapper cobalt
#

!pypi google-trans-new

unkempt canyonBOT
slate swan
#

doest it show the flags

boreal ravine
slate swan
#

yes

boreal ravine
#

ig yes

slate swan
#

doesnt work for me

dim cedar
slate swan
#

but it works on a bot

dim cedar
#

even after pip

slate swan
#

do you know how to connect a webhook to a bot ?

boreal ravine
boreal ravine
slate swan
#

the flags don't send when im on a webhook

#

but it sends when i use bot

boreal ravine
#

i dont understand

opal pewter
#

Im switching to a new editor so idk

boreal ravine
dim cedar
slate swan
#

ok for exeample if i want to fetch someones badge, if they have the badge it will say true if they dont have it will say false @boreal ravine

dim cedar
#

the main error is 'None type' object has no attribute "group"

lethal heart
#

Kk

opal pewter
boreal ravine