#discord-bots

1 messages · Page 652 of 1

jade tartan
#

Can get variable be define on the member join event?

spring flax
#

to get the guild that the member joins, just use member.guild no need to do client.get_guild to get the guild object

sick birch
#

Depends on the context

prisma spoke
#

SQL

#

No such lines

upbeat otter
#

Try using an if else statement to check in an underscore is there or not, then loop through the lost words and check if any of them contain an underscore and split them from the underscore and replace the underscore with empty strings

#

Change the variable names 'cause every time you define "role" variable it overwrites the previous role variable

prisma spoke
#

.. Please anyone?

clear pebble
#

can someone help me ? there's error but i couldn't fix it

import discord
import asyncio
import time
import random

client = discord.Client()
TOKEN = ''

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

@client.event
async def on_message(message):
  if message.author == client.user:
    return

  if message.content.startswith('阿巴阿巴'):
    await message.channel.send('阿巴')

  if message.content.startswith('滚'):
    await message.channel.send('蛋')

@client.command()
async def nick(ctx, m: discord.Member, *, newnick):
  await m.edit(nick=newnick)
  await ctx.send('done')

#(whateverprefix)nick @.useruwant newnickname



client.run(TOKEN)
slate swan
#

you cannot use .command() with discord.Client

maiden fable
#

Facts

prisma spoke
final iron
untold token
slate swan
unkempt canyonBOT
#

class discord.ext.commands.Bot(command_prefix, help_command=<default-help-command>, description=None, **options)```
Represents a discord bot.

This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") and as a result anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") you can do with this bot.

This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality to manage commands.
clear pebble
#

where's on message event?

untold token
#

I know

#

I was just pointing it out

slate swan
#

use this instead of discord.Client

clear pebble
#

ok

untold token
#

If they to commands.Bot

clear pebble
#

how?

slate swan
untold token
# clear pebble ok

commands.Bot is a subclassed version discord.Client with more features

clear pebble
untold token
#

and it comes with a commands framework

clear pebble
#

e....

#

can someone help me change it?

slate swan
clear pebble
#

don't really understand

untold token
#
import discord
from discord.ext import commands


bot = commands.Bot(command_prefix='!', intents=discord.Intents.all()) 

@bot.listen()
async def on_ready():
    """Called when the client is done preparing the data received from Discord."""
    print("Bot is ready")

@bot.command()
async def test(ctx):
    """A test command"""
    await ctx.send("test")

@bot.listen()
async def on_message(message):
    """Called when a Message is created and sent."""
    if message.author.bot:
        return
    ... # your code

bot.run(token) 
#

Here is a simple example

clear pebble
#

oh thanks

untold token
#

You cannot dm an user if they are not in mutual guilds with the bot

#

and just

forest lion
#

I mean I’m using the command to add myself to the list

#

And it’s reading my commands and adding

untold token
#
member = ctx.guild.get_member(ID)
await member.send(content="Hello")
#

Would work

slate swan
#

@sick birch

#

Hello all

untold token
#

If the bot cannot DM, it is going to raise a Forbidden Exception

slate swan
#

No module httpx but there is a module httpx. Any ideas?

untold token
#

You can use try except to catch it

sullen shoal
orchid sapphire
#

hi @sullen shoal

sullen shoal
#

hello

orchid sapphire
#

can i ask a question ? im not sure whether its related to python or not

slate swan
sullen shoal
#

yea sure

final iron
orchid sapphire
#

like recently i just play a discord game called erpg,

slate swan
orchid sapphire
#

and i have a mind map right now , is it possible to use python to solve human verification ?

sullen shoal
#

recaptcha?

orchid sapphire
#

can i put screenshots here ?

slate swan
#

if that's the asqlite designed by danny , you'd be using git

sullen shoal
#

show

slate swan
orchid sapphire
final iron
orchid sapphire
orchid sapphire
final iron
#

Yeah, no

#

!rule 5

unkempt canyonBOT
#

5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.

final iron
#

Read this

slate swan
#

Asqlite module not install

#

How to do that

orchid sapphire
#

i dont know its breaking the rules

#

im sorry

sullen shoal
#

its kinda self botting

glass rock
#

how can I use images I stored on my PC on somehost?

maiden fable
#

Istg I'mma KMS now

slate swan
#

Who asking for a selfbotM

#

?

orchid sapphire
#

let me google it up what is a self bot

final iron
maiden fable
slate swan
maiden fable
#

They can

maiden fable
unkempt canyonBOT
final iron
slate swan
slate swan
final iron
#

It's extremely simple code to do that

sullen shoal
#

simple if statement on on_message is enough

slate swan
sullen shoal
#

yes

#

if not then process the commands

glass rock
#

does anyone else use somehost here?

maiden fable
#

So i have something like, I have a folder named utils and inside of it, a file named constants.py. So, how can I import from that constant file? I tried from utils.constants import * but says no module named utils and when I add a period before utils, it raises an ImportError

slate swan
slate swan
unkempt canyonBOT
#

Hey @slate swan!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

final iron
glass rock
slate swan
#

pip install git+https://github.com/Rapptz/asqlite.git

maiden fable
slate swan
maiden fable
sullen shoal
#

.utils.constants

slate swan
#

you'd be using from .utils.constants import *

maiden fable
sullen shoal
#

thats how every bot works tho

slate swan
#

Hello. Wondering how to solve this. Brotli is installed. Any ideas?

sullen shoal
#

try again

glass rock
maiden fable
#

Yea lemme try again

slate swan
glass rock
slate swan
slate swan
final iron
untold token
#

ping?

slate swan
#

other than making your own api with flask and getting those images with raw requests lol

glass rock
final iron
untold token
#

from .utils import constant

slate swan
untold token
#

You are using discord.Client

maiden fable
magic ore
untold token
#

If you want to use the commands framework

#

then use commands.Bot

final iron
#

Shit

slate swan
untold token
#

!d discord.ext.commands.Bot

unkempt canyonBOT
#

class discord.ext.commands.Bot(command_prefix, help_command=<default-help-command>, description=None, **options)```
Represents a discord bot.

This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") and as a result anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") you can do with this bot.

This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality to manage commands.
final iron
unkempt canyonBOT
#

5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.

slate swan
#

How is it breaking law

valid galleon
#

so im using a sqlite db to store afk members' ids. Is there any way to check if the user mentioned in a message is the same as the afk person?

final iron
slate swan
#

Never knew that but ok

untold token
#
import discord
from discord.ext import commands


bot = commands.Bot(command_prefix='!', intents=discord.Intents.all()) 

@bot.listen()
async def on_ready():
    """Called when the client is done preparing the data received from Discord."""
    print("Bot is ready")

@bot.command()
async def test(ctx: commands.Context):
    """A test command"""
    await ctx.send("test")

@bot.listen()
async def on_message(message: discord.Message):
    """Called when a Message is created and sent."""
    if message.author.bot:
        return
    ... # your code

bot.run(token) 

A simple example of commands.Bot framework

sullen shoal
untold token
#

instead of using on_message to make commands

#

use the commands framework

#

Easier and much better

slate swan
#
if "CustomActivity" == str(member.ActivityType.type):``` any alternatives for this?
slate swan
untold token
#

Yes and use commands.Bot

valid galleon
untold token
#

!d discord.ext.commands.Bot

unkempt canyonBOT
#

class discord.ext.commands.Bot(command_prefix, help_command=<default-help-command>, description=None, **options)```
Represents a discord bot.

This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") and as a result anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") you can do with this bot.

This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality to manage commands.
slate swan
#

and initiate the bot with bot = commands.Bot

untold token
#

Refer to this

orchid sapphire
#

@sullen shoal its quite rude to ask but can i dm u ? need to ask more regarding my question

#

its okay if u dont want hahaha

slate swan
#
if "CustomActivity" == str(member.ActivityType.type):``` any alternatives for this?
untold token
#

Just send it hwre

untold token
#

More people can help

slate swan
slate swan
sullen shoal
slate swan
#

i have act defined btw

untold token
#
if isinstance(..., ...):
   ...  # do something 
forest lion
untold token
slate swan
#

mhm

orchid sapphire
#

im new in coding , what i wanna ask is why self botting is against the TOS? isnt the uses of bot is to make our life easier ?

#

please correct me

untold token
#

you could use a task loop

slate swan
sullen shoal
slate swan
untold token
#

Huh

slate swan
#
 python main.py
WARNING:discord.client:PyNaCl is not installed, voice will NOT be supported
cogs.config can not be loaded:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 606, in _load_from_module_spec
    spec.loader.exec_module(lib)
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/runner/Acrylic-Original/cogs/config.py", line 65, in <module>
    class config_buttons(discord.ui.View):
AttributeError: module 'discord' has no attribute 'ui'

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

Traceback (most recent call last):
  File "main.py", line 149, in <module>
    raise e
  File "main.py", line 146, in <module>
    bot.load_extension(cog)
  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 609, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.config' raised an error: AttributeError: module 'discord' has no attribute 'ui'
untold token
#

This

#

Code?

#

Where is the error generating from

forest lion
#

Functionality first

#

Also, when I remove literally everything except for print, that doesn’t work either

untold token
#

Do the other commands in your bot works?

forest lion
#

It’s commands.Cog.listener(), right?

untold token
#

Yes

forest lion
#

Yeah all of them

#

And on_ready(self)

untold token
#

Okay well, I could be wrong, but I think your bot is getting disconnected from the Gateway

forest lion
#

Yeah, it’s still connected

untold token
#

When you are making that much requests

forest lion
#

It’s literally just print at this point

untold token
forest lion
#

No no, it responds to ever single command

#

That I’m ready event does not work at all

#

Only thing

untold token
#

Bruh no

#

why do you have client and bot

#

just use a single bot constructor

#

commands.Bot

forest lion
#

You can do bot.event btw

#

Instead of client.event

untold token
#

bot.listen() is better

#

when it comes to on_message events

#

It's an external asynchronous listener

forest lion
#

bot.command is right

untold token
#

commands.Bot is your constructor

#

bot.command() is how create and register a command

untold token
#

I am using bot.listen() for on_message events

#

Use that

#

I can explain you why but its going to be very long

#

So I am gonna put this in short

forest lion
#

Line 21 you can change that bot = part to whatever you want

#

And then just call commands like that

sullen shoal
# forest lion That I’m ready event does not work at all

on_ready event is called multiple times when the bot gets disconnected. its not completely ready to be able to send messages and stuff when its called.

This function is not guaranteed to be the first event called. Likewise, this function is not guaranteed to only be called once. This library implements reconnection logic and thus will end up calling this event whenever a RESUME request fails.

use commands.tasks instead

forest lion
#

Just make it consistent

untold token
#

listeners (.listen()) and commands.Cog.listener() are asynchronous and external event listeners

#

That means, a listener doesn't override the default event but actually listen to the event as an external source

#

When you create a listener, it adds the event listener to bot and when the bot receives an event, it passes the event data to all the listeners that you created

gaunt ice
#

when I create an event in main like on_message I can't use other commands

forest lion
#

I’m not sure how to use commands.task, never seen that before
Maybe I have idk, does anyone have a link

untold token
gaunt ice
#

how do u fix that

untold token
#
@bot.listen("on_message")
async def message_listener(message: disnake.Message):
   ...  #  code here 
#

You can listeners

forest lion
#

Not an on message

visual island
#

oops

untold token
#

They are external and they do not block each other

forest lion
#

And my commands work

visual island
#

wrong message

forest lion
#

All good

forest lion
#

Thank you

untold token
#

Yeah that is good enough

#

I could explain on detail the differences between listeners and events

#

But that's lengthy

forest lion
#

Oh you want me to make a loop?

untold token
#

And I am lazy

forest lion
#

Didn’t want to do that though hmm

sullen shoal
#

you can cancel the loop when the work is done

untold token
#

So

sullen shoal
#

use Bot.wait_until_ready

#

there is an example there showcasing that

untold token
#
@tasks.loop(count=1)
async def task(self):
   await self.bot.wait_until_ready()
   ...  # code here
#

This will execute the loop once

#

because of the count kwarg

forest lion
#

I see

#

Here let me try this and report back

untold token
#

That's because db is None

#

Are you using replitdb outside of replit?

forest lion
#

good day to learn something new, never used tasks.loop

untold token
#

That won't work

#

replitdb only works inside replit

#

or a repl

#

You cannot use anywhere else

#

you want a database like that

#

MongoDB is your best bet

sullen shoal
#

replit db isnt async afaik

untold token
#

Yeah that too

#

This explains how MongoDB works and how you can use it

#

It uses pymongo

#

but you need motor

#

Which is the asynchronous counterpart of pymongo

#

Now personally I don't like this

forest lion
#

no errors on console

#
    @tasks.loop(count=1)
    async def task(self):
        await self.client.wait_until_ready()
        for i in queue:
            print("just testing to see if this works")```
slate swan
#
    @commands.Cog.listener()
    async def on_member_update(self,before, after):       
        guild = self.bot.get_guild(645753561329696785)
        member = after
        if after in guild.members:
            if 'a1b2c3' in str(after.activity):
                role = guild.get_role(916271809333166101)
                await after.add_roles(role)
            else:
                role = guild.get_role(916271809333166101)
                await after.remove_roles(role)

Hey why do I get the error
discord.errors.NotFound: 404 Not Found (error code: 10011): Unknown Role
The role ID is correct

forest lion
#

im gonna do try: and print errors

untold token
sullen shoal
untold token
#

^

#

you need to start it

slate swan
untold token
#

await task.start()

final iron
untold token
#

Either in on_ready or a command

forest lion
#

mmm

#

maybe not

sullen shoal
slate swan
#
        if guild.get_member(member.id) is not None:
            rich_presence = ":rich_presence:"
            acts = member.activities
            if member.activity is None:
                act = 'None'
    
            else:
                activity_name = member.activity.name

            a = ActivityType

            if member.activity != None:
                act = f'{member.activity.type}'.replace("ActivityType.playing", f"Playing {activity_name} {rich_presence}").replace("ActivityType.listening", f"Listening to {activity_name} {rich_presence}").replace("ActivityType.watching", f"Watching {activity_name} {rich_presence}").replace("ActivityType.streaming", f"Streaming {activity_name} {rich_presence}").replace("ActivityType.competing", f"Competing in {activity_name} {rich_presence}").replace("ActivityType.custom", f"{activity_name}")
            if isinstance(act, discord.CustomActivity):
                act = f'{activity_name} {rich_presence}'```basically trying to make the bot get status, if status is custom but rich presence is detected (playing, watching, ect), than output is (custom status + rich presence emote). if status is not custom but rich presence is detected, output is (activity type + activity name + rich presence emote). if no status at all, output is 'None'
slate swan
sullen shoal
#

i still doubt

slate swan
#

alr sent the role id proof above walk

sullen shoal
#

tbh if smth like happens to me, i just delete the code and code it again with few extra brain cells and it magically starts working

untold token
#

try using fetch

slate swan
#

I tried rebooting the bot thinkcat

untold token
#

it's an API call and a coroutine

slate swan
#

okay

untold token
#

So you need await it

forest lion
#
class bdsp(commands.Cog):
    def __init__(self, client):
        self.client = client
        self.trader.start()

# Sysbot.py
    @tasks.loop(count=1)
    async def trader(self):
        await self.client.wait_until_ready()
        try:
            for i in queue:
                print("just testing to see if this works")
                # other stuff im asking the bot to do```

still not printing
untold token
#

await ctx.guild.fetch_role()

forest lion
#

didnt print exception either

untold token
#

global one?

sullen shoal
forest lion
#

I dont have a global one

sullen shoal
#

i dont see queue defined

forest lion
#

geez idk what im doing anymore

slate swan
#
        if guild.get_member(member.id) is not None:
            rich_presence = ":rich_presence:"
            acts = member.activities
            if member.activity is None:
                act = 'None'
    
            else:
                activity_name = member.activity.name

            a = ActivityType

            if member.activity != None:
                act = f'{member.activity.type}'.replace("ActivityType.playing", f"Playing {activity_name} {rich_presence}").replace("ActivityType.listening", f"Listening to {activity_name} {rich_presence}").replace("ActivityType.watching", f"Watching {activity_name} {rich_presence}").replace("ActivityType.streaming", f"Streaming {activity_name} {rich_presence}").replace("ActivityType.competing", f"Competing in {activity_name} {rich_presence}").replace("ActivityType.custom", f"{activity_name}")
            if isinstance(act, discord.CustomActivity):
                act = f'{activity_name} {rich_presence}'```basically trying to make the bot get status, if status is custom but rich presence is detected (playing, watching, ect), than output is (custom status + rich presence emote). if status is not custom but rich presence is detected, output is (activity type + activity name + rich presence emote). if no status at all, output is 'None'
untold token
gaunt ice
#

but I am not in pc now ;-;

forest lion
gaunt ice
#

who's good at cogs

forest lion
#

queue is defined on line 42

rain olive
gaunt ice
#

YES

rain olive
#

sure

gaunt ice
#

I DO NEED

#

BRB

forest lion
#

line 441 is the command im using to add myself to the queue

#

and I know its adding me to it

untold token
gaunt ice
slate swan
#
 python main.py
Traceback (most recent call last):
  File "main.py", line 32, in <module>
    from cogs.extra import extra
  File "/home/runner/Tirex-Safety-1/cogs/extra.py", line 3, in <module>
    from utils.Buttons import ButtonPlate
ModuleNotFoundError: No module named 'utils.Buttons'
exit status 1
#

Utils.buttons

sullen shoal
#

k

slate swan
sullen shoal
#

nicer way to say whats the problem

slate swan
#
        if guild.get_member(member.id) is not None:
            rich_presence = ":rich_presence:"
            acts = member.activities
            if member.activity is None:
                act = 'None'
    
            else:
                activity_name = member.activity.name

            a = ActivityType

            if member.activity != None:
                act = f'{member.activity.type}'.replace("ActivityType.playing", f"Playing {activity_name} {rich_presence}").replace("ActivityType.listening", f"Listening to {activity_name} {rich_presence}").replace("ActivityType.watching", f"Watching {activity_name} {rich_presence}").replace("ActivityType.streaming", f"Streaming {activity_name} {rich_presence}").replace("ActivityType.competing", f"Competing in {activity_name} {rich_presence}").replace("ActivityType.custom", f"{activity_name}")
            if isinstance(act, discord.CustomActivity):
                act = f'{activity_name} {rich_presence}'```basically trying to make the bot get status, if status is custom but rich presence is detected (playing, watching, ect), than output is (custom status + rich presence emote). if status is not custom but rich presence is detected, output is (activity type + activity name + rich presence emote). if no status at all, output is 'None'
untold token
#

.utils

#
from .utils import stuff
slate swan
forest lion
#

idk if im missing anything more, if I incorporate it into the other command it works

untold token
forest lion
#

But if you guys can tell its controlling other device

gaunt ice
#

error:Traceback (most recent call last): File "main.py", line 30, in <module> bot.load_extension("cogs.music1") 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 623, in _load_from_module_spec raise errors.ExtensionFailed(key, e) from e discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.music1' raised an error: CommandRegistrationError: The alias current is already an existing command or alias. code:```
bot.load_extension("cogs.tictactoe")
bot.load_extension("cogs.economy")
bot.load_extension("cogs.music1")

untold token
#

or

slate swan
#

@untold token still having the same error dead

untold token
slate swan
untold token
#

It's not a cog issue but a command issue

gaunt ice
#

but there isnt any other command like that in main

untold token
#

use .utils

boreal ravine
untold token
#

that's how import stuff from utils directory

gaunt ice
#

ohhh

#

OMG

untold token
#

Yeah

boreal ravine
untold token
#

You have the command twice

slate swan
untold token
#

You don't have module.exports in python

untold token
slate swan
# boreal ravine whats the issue?

if you have rich presence, so streaming playing watching ect, but custom status at the same time, i want my bot to send their custom status followed with the rich presence emote

untold token
#

Yes, like cogs

forest lion
#

you guys giving up? 😅

untold token
#

You can multiple commands in a single cog

boreal ravine
slate swan
#

but if they have custom status with NO rich presence, than the output is just the status

gaunt ice
slate swan
untold token
#

Yeah

untold token
slate swan
slate swan
#

but i think ive formatted it wrong

forest lion
boreal ravine
slate swan
#

one sec lemme get a few screenshots to show what i mean

untold token
slate swan
#

and no, no errors

boreal ravine
#

hm

untold token
#

Fetch doesn't fail

slate swan
forest lion
slate swan
forest lion
#

thats how bad lmao

untold token
slate swan
#

@boreal ravine make sense?

slate swan
untold token
#

Member and Presence?

slate swan
#

Both yes

forest lion
#

oh... lmfao

untold token
#

Okay

forest lion
#

first time using the site, my bad

#

didnt realize you can change it lmao

slate swan
boreal ravine
slate swan
#

Means help

untold token
#

Uh

slate swan
untold token
#

Code?

slate swan
#

sec, ill get another ss

untold token
#

Errors?

slate swan
#

see

untold token
#

Why is it giving an unknown role error

#

You are not passing the Role ID as a string right?

slate swan
#
import discord
from discord.ext import commands
from .utils import stuff
from discord import ui

class HomeButton(ButtonPlate):
    async def callback(self, interaction): # callback is basically the built in event handler for the button instantiated by the individual class
        view = self.view
forest lion
#

but anyways kayle, line 79 its not printing

forest lion
#

so idk what I messed up

boreal ravine
#

hm

untold token
#

it was an example

slate swan
#

@boreal ravine

untold token
#

from .utils import stuff

slate swan
untold token
#

stuff meant your modules and files to import

untold token
slate swan
#

@untold token i share you replit kink

#

Dm

boreal ravine
untold token
slate swan
slate swan
untold token
#

Btw do you know basic python?

#

That's a basic python issue

#

and you seem to lack that

#

You should learn python before making bots

untold token
#

The you need to import like this

#
from .utils.buttons import bla bla
#

Like that

slate swan
#

@untold token This is also causing a memory leak 💀

slate swan
#
            rich_presence = ":rich_presence:"
            acts = member.activities
            activity_name = member.activity.name```
if user has rich presence (streaming watching listening to, ect):
output is (activity name + type + rich_presence)

if user has custom status:
output is (activity.name)

if user has custom status but rich presence:
output is (custom status activity.name + rich_presence) @boreal ravine
#

does that make more sense of what my objective is or

boreal ravine
#

hm

boreal ravine
slate swan
#

when I add the on_member_update listner and the code the number of tasks go from 5 to uh a lot..

slate swan
#

hopefully that makes sense lol

boreal ravine
#

ah

#

so it doesnt show the rich presence?

slate swan
#

yep

boreal ravine
#

hm

slate swan
#

do you need the src again or

boreal ravine
#

you dont send the activity name + custom status

slate swan
#

so just isinstance(act)?

normal ginkgo
#

What do I need to make a bot like invitemanager?

boreal ravine
# slate swan so just isinstance(act)?

isinstance takes 2 arguments lol, and you can check for a variable using isinstance. have you tried checking if the author has a rich presence and a custom status if so send it?

slate swan
#

or at least what its meant to do

boreal ravine
#

hm

boreal ravine
slate swan
forest lion
#

Hey kayle, did you ever get a chance to look at the code or nah

maiden fable
boreal ravine
boreal ravine
forest lion
#

haha, all good

forest lion
#

Its cool because it controls my nintendo switch

untold token
#

Can you show your code?

boreal ravine
maiden fable
maiden fable
slate swan
maiden fable
#

The import line is there

untold token
#

doesn't work?

boreal ravine
maiden fable
slate swan
#

aw fuck

#

that leads me back to another problem

untold token
maiden fable
#

I need an init file for that or something?

slate swan
#

ActivityType.custom is an str

#

not an attribute

untold token
#

Try with in init file ye

maiden fable
boreal ravine
#

!d discord.ActivityType.custom

slate swan
unkempt canyonBOT
boreal ravine
maiden fable
#

!d enum.Enum

unkempt canyonBOT
#

class enum.Enum```
Base class for creating enumerated constants. See section [Functional API](https://docs.python.org/3/library/enum.html#functional-api) for an alternate construction syntax.
maiden fable
untold token
#

I did tell em this

slate swan
#

so py list_ = discord.ActivityType.playing, discord.ActivityType.streaming, discord.ActivityType.watching, discord.ActivityType.listening, discord.ActivityType.competing if discord.ActivityType.custom and x in list_:

peak loom
#

It says unused but I clearly use it.

untold token
#

No......

peak loom
#

How do I fix?

maiden fable
# untold token No you can't

So if I also have a cogs folder in the same directory as the utils one, how do I import stuff from utils.constants into one of the cog file?

untold token
maiden fable
#

My discord died 😐

boreal ravine
maiden fable
untold token
#

Then give it some other name ig

boreal ravine
untold token
#

maybe

#

bot_utils

maiden fable
#

Wym

#

Why tho

untold token
#

Well I forgot the exact reason why you need to do .utils in order to import stuff

maiden fable
#

Istg I fucking hate import errors

untold token
#

Lol

untold token
slate swan
untold token
#

from constants import *

#

That should work imo

#

But try it and see

peak loom
boreal ravine
#

thats why its green

untold token
peak loom
untold token
#

If you want multiple on_ready events

peak loom
untold token
#
@bot.listen()
async def on_ready():
   ...  #  code 
peak loom
untold token
#

with this, it creates an external event listener that listen to an on_ready event

#

and you can use multiple of them

peak loom
#

Okay.

untold token
#

oops

#

!d discord.ext.commands.Bot.listen

unkempt canyonBOT
#

@listen(name=None)```
A decorator that registers another function as an external event listener. Basically this allows you to listen to multiple events from different places e.g. such as [`on_ready()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_ready "discord.on_ready")

The functions being listened to must be a [coroutine](https://docs.python.org/3/library/asyncio-task.html#coroutine "(in Python v3.9)").

Example...
untold token
#

There

peak loom
untold token
#

Wdym doesn't fix your problem

#

code?

#

Errors?

slate swan
#

!app

#

!pip

unkempt canyonBOT
#
Missing required argument

package

#
Command Help

!pypi <package>
Can also use: pack, package, pip

Provide information about a specific package from PyPI.

peak loom
untold token
#

Uh

#

That's not proper

#

I can't even see properly

#

did you use .listen()?

peak loom
#

Fix your eyes.

#

Si.

peak loom
untold token
#

Then ignore that warning

#

It will work

untold token
burnt inlet
#

@client.event async def on_member_join(member): role = discord.utils.get(member.server.roles, id="916758393132306463") await client.add_roles(member, role)

#

are my code right?

#

i want if a member join its gonna add role

forest lion
#

ok im def messing this part up
for i in queue: this is where the command stops working

burnt inlet
#

yah i code this for my server only 🙂

untold token
#

this is old

#

First of all its member.guild

#

not member.server

#

then its member.add_roles(role)

peak loom
novel apexBOT
#

This is not a Modmail thread.

#

This is not a Modmail thread.

untold token
#

Not a string

peak loom
weary gale
#

why doesnt this work?

untold token
untold token
#

This is wrong

untold token
#

it's an int

#

not a string

peak loom
weary gale
#

how can you call yourself a bot coder???

peak loom
#

add_roles.

untold token
#

add_reaction is a method of the message object

weary gale
#

ok 13 yro

weary gale
peak loom
untold token
weary gale
#

yeah

untold token
weary gale
peak loom
slate swan
#

if a members name is "Hello" and i use a command where an argument is a member, and i type the name "hello" instead of "Hello", how can i make it work for both cases? instead of raising the infamous "member not found" error

untold token
#

Your code is entirely wrong

weary gale
peak loom
untold token
#
channel = bot.get_channel(ID)
message = await channel.send("stuff")
await message.add_reactions("emoji here")
#

That's how you do it

untold token
reef shell
untold token
#

Because it uses, old methods and attributes

#

Which are deprecated

#

its member.guild

weary gale
#

can somebody please help me with this

untold token
#

not member.server

untold token
#

For your bot application

reef shell
untold token
#

and yeah that too

#

Looks weird

untold token
weary gale
#

what

untold token
#

Do you have any other on_member_join event?

weary gale
#

oh can i only have one

untold token
untold token
#

Then yes

weary gale
#

oh

untold token
#

You should use .listen()

weary gale
#

ok thx

untold token
#

to have multiple listeners

reef shell
untold token
#
@bot.listen()
async def on_member_join(member: discord.Member):
   ...  # code here
#

This creates an external listener that listens to this event

#

and because they are external, you can have multiple listeners of the same event type

untold token
#

Yes

weary gale
#

thanku sm

#

oh wait wtf it doesnt work

untold token
#

Wdym doesn't work

weary gale
#

do i have to uncheck member intents?

untold token
#

Errors?

untold token
weary gale
untold token
#

Wait

#

Do you have an another on_member_join event?

weary gale
#

yeah

untold token
upbeat otter
untold token
# weary gale yeah

Did you change it from an event to a listener
So bot.event to bot.listen()?

untold token
untold token
#

Hmm

upbeat otter
#

isnt it discord.ext.commands.Bot?

untold token
#

Oh shit

#

I didn't notice that

#

its commands.Bot

#

not discord.Bot

#

Loool

untold token
upbeat otter
#

and its bot.event since you are not in a cog

untold token
#

You can use bot.listen in non cogs too

upbeat otter
#

if you really wanna use discord module use discord.Client

upbeat otter
untold token
#

commands.Cog.listener() is the sub classed version of Bot.listen()

upbeat otter
untold token
#

and I encourage bot.listen() because it's an external asynchronous event listener, which doesn't overrides the default event

weary gale
#

so this is what i have and it doesnt work

untold token
#

see .event overrides the default event with your custom event

upbeat otter
#

,-,

untold token
#

but a listener is external

upbeat otter
#

thank though

untold token
#

When you create a listener, it adds the listener into the Bot instance and when the bot receives an event, it passes the event and data to all the listeners you created

weary gale
#

still doesnt work?

#

im confused

upbeat otter
weary gale
untold token
#
@bot.event
async def on_message(message):
    ...  # code
    await bot.process_commands(message)
upbeat otter
#

@weary gale Atleast add a command prefix

#

that may cause errors

weary gale
#

oh wait

#

i think im stupid

untold token
#

The reason why you call process_commands in a event is because your event will override the default event that dpy uses

weary gale
#

this isnt possible right

untold token
#

process_commands is the method that process the message that is recieved and the checks if the message content is a command with prefix that was set

#

If there is any, it will execute the function related to name of the command that you set

#

but that's not the case in a listener

#
@bot.listen()
async def on_message(message):
   ...  # code here
#

In here, you don't need to call process_commands

#

Because this is an external listener which doesn't override the default message event

#

and if you call process_commands regardless

#

your commands will execute twice

#

that's because dpy is already processing your message and then executing the function related to it

#

and when you add process_commands method

#

you are doing it too

weary gale
untold token
shadow wraith
#

dont use replit unless your project is private

weary gale
#

why

untold token
#

Hmm replit for bot hosting

shadow wraith
untold token
#

Not good

shadow wraith
#

if people find your project

weary gale
untold token
weary gale
untold token
#

but if it is set directly in the code as a string

#

Then yes

#

They people can see it

weary gale
#

so what
Bot = commands.Bot(commands_prefix=iforgotiforgotiforgot)

shadow wraith
maiden fable
untold token
maiden fable
#

Haha yups

shadow wraith
untold token
#

^

shadow wraith
#

and you can use client but i ditched it

#

typing bot is way more faster than client

untold token
#

Proper naming

weary gale
#

to lowercase

untold token
#

Yes

weary gale
#

f

shadow wraith
#

oh yeah

#

just do find and replace

untold token
#

^

weary gale
#

what hwo

#

how

shadow wraith
#

crab you use replit i forgot

untold token
#

ctrl + f

shadow wraith
#

^

untold token
#

In replit

#

expand it

shadow wraith
#

or if your on mac, command+f

untold token
#

and you have the replace option too

shadow wraith
#

to replace you have to do it manually??? 🤔

untold token
#

Nah

#

ctrl + f opens both search and replace

shadow wraith
#

💀

weary gale
#

this has to be capital right?

shadow wraith
#

mhm.

weary gale
#

im too smart

untold token
#

Lamo

weary gale
#

and this

#

capital?

untold token
#

No..

weary gale
#

oh

untold token
#

small

#

breh its literally highlighted as an error

weary gale
#

no thats when i do ctrl + f

#

and find bot

#

Bot*

slate swan
#
display_name = "Test1"
user_name = "Test2"
user_id = "Test3"

connection_string = (
    r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
    r'DBQ=C:\Users\samjo\Documents\Database2.accdb;'
    )
connection = pyodbc.connect(connection_string)
crsr = connection.cursor()

sql='''INSERT INTO accounts ([Display Name], [User Name], [User ID]) VALUES (?,?,?)'''
crsr.execute(sql, (f"{display_name}", f"{user_name}", f"{user_id}"))
connection.commit()

client.run(token_id)

This works, But I want to loop into everyone in the server and get there dispay_name, user_name, user_id and then put it into the database, Can anyone help please?

weary gale
#

@untold token so do i have to move the autorole command to main.py?

#

or can i leave it

untold token
#

And then load the cog

weary gale
#

this is its current state, and it still doesnt work

untold token
#

commands.Bot(intents=intents)

#

you didn't pass command_prefix

weary gale
#

what

weary gale
untold token
#

command_prefix is a required argument

#

you need pass it

weary gale
#

so just that command_prefix

untold token
#

Like a prefix

weary gale
#

i cant remember hwo

weary gale
#

forgor

untold token
#

@weary gale

#

Yes that

slate swan
untold token
slate swan
#

Microsoft Access

untold token
#

Never heard of that kind of database

slate swan
#

how?

#

ok that doesn't matter

#

what matters, Is I want to get user_id, display_name, and user_name

untold token
#

Well is pyodbc isn't asynchronous

#

It will block your async code

slate swan
#

-_-

untold token
slate swan
#

I think

untold token
#

Well I can't help you with Microsoft access, I have never used that database

#

I mostly use postgres

slate swan
#

urgh

untold token
#

and mongoDB

slate swan
#

Can you tell me how to get user_id and user_name

#

at the same time

#

for the same user?

#

And then print it out as a string?

#

for example

untold token
#

If you want to get the data from the table

slate swan
#
for user in guild.members:
    print(user_id, member.username)
quartz void
#

@slate swan you want to add everyone in the guild to a database?

slate swan
#

No I want to insert

untold token
#

Ah I see

quartz void
#

and you need the user id and name?

slate swan
untold token
#

Then you need use the insert statement

slate swan
#

yes I know but how?

untold token
slate swan
#

we need a for loop

weary gale
#

i nearly ruined my bot

quartz void
#

what exactly do you need from the name
do you want tea#9576 or just tea

untold token
#

do get member name and disrim

#

if you want the ID

untold token
slate swan
#

tea is display_name

weary gale
#

@untold token still doesnt work

untold token
#

If you want the whole user name
Then
str(member) returns member name like this
name#1234

#

So

quartz void
#
user_id = member.id
user_name = str(member)
untold token
#
member_name = str(member)
member_id = member.id
slate swan
#

okay

weary gale
#

doesnt work?

untold token
slate swan
#

now we need a for loop

#

That will loop and get there username and userid

untold token
slate swan
#

and insert it

slate swan
quartz void
untold token
#

^

#

and change prefix to something else

#

that was just an example

untold token
#

Wherever you want

weary gale
untold token
#

But

#

@slate swan pyodbc is not asynchronous

#

It will block your bot

slate swan
#

how

untold token
#

once it's making a request

#

Look for an asynchronous counterpart

weary gale
#

i just dont understand why it doesnt work

slate swan
#
guild = client.get_channel(756504534897000528)

for member in guild.members:
    
untold token
# slate swan how

if you use synchronous libraries in asynchronous code, it will block the entire process

slate swan
#

Will this work?

untold token
#

You need a guild

slate swan
untold token
#

so it would be client.get_guild()

quartz void
slate swan
weary gale
slate swan
#
guild = client.get_guild(756504534897000528)
for member in guild.members:
    print(member)
#

will this work?

quartz void
weary gale
untold token
#

and yes it work

#

if you want the name

weary gale
untold token
#

then

weary gale
#

well event

slate swan
#
  File "d:\Desktop\MaxTheBot\bot.py", line 106, in <module>
    for member in guild.members:
AttributeError: 'NoneType' object has no attribute 'members'
quartz void
untold token
#
guild = client.get_guild(756504534897000528)
for member in guild.members:
    print(str(member))
weary gale
untold token
#

You are using the channel ID as the guild ID

slate swan
quartz void
untold token
#

Channel ID is different and guild ID is different

weary gale
quartz void
#

and also change the Intents in your code

slate swan
#

yes I know

weary gale
#

wdym

quartz void
#

you currently use Intents.default

slate swan
#

@quartz void he doesn't know what are intents

slate swan
untold token
#

Same ID

slate swan
#

omg, It's the guild_id

#

That's not wrong

#
    for member in guild.fetch_members():
AttributeError: 'NoneType' object has no attribute 'fetch_members'
untold token
#

Well its returning None

slate swan
#

wait

#

I need an event -_-

untold token
quartz void
#
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(intents = intents, ...)

@weary gale

untold token
#

It's just enabling the members intents

quartz void
untold token
#

Yeah that

#

Or just enable all the intents

weary gale
#

so this?

weary gale
untold token
#

discord.Intents.all()

untold token
weary gale
#

idk why it doesnt owkr

#

work

untold token
#

Is the name of role correct?

weary gale
#

yep

untold token
#

are your sure

#

Use the Role ID instead

weary gale
#

ok

untold token
#

member.guild.get_role(role_ID)

#

Much more accurate and reliable

weary gale
#

where

#

do i put that

untold token
#

!d discord.Guild.get_role

unkempt canyonBOT
weary gale
#

does it matter?

untold token
#

Yes it does

weary gale
#

where i put it

untold token
weary gale
#

yeahj

slate swan
#
    for member in guild.members():
TypeError: 'list' object is not callable
#

new errorrrrr

untold token
#

its guild.members

#

it returns a list

weary gale
untold token
#

it's an attribute not a method

slate swan
#

what do I do?

untold token
untold token
slate swan
#

ayyyy it works

untold token
#

Cool

untold token
#

BRUH

weary gale
#

i dont understoodenating

untold token
#

I'm done

weary gale
#

no pls

untold token
#

Bye

slate swan
#

understoodenating

weary gale
#

dont giveup on us

slate swan
#

send me your code, I gotta spoonfeed

weary gale
#
from discord.ext import commands

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

bot = commands.Bot(intents = intents, command_prefix = ["$", "$"])

@bot.listen()
async def on_member_join(member):
    autorole = discord.utils.get(member.guild.roles, name = 'thisissupposedtobetheroleid')
    await member.add_roles(autorole)```
slate swan
#

@weary gale copy your code and send it

untold token
#

Bruh like literally

weary gale
#

@slate swan i sent it

slate swan
#

why does he have a fucking listen?

untold token
#
autorole = member.guild.get_role(ID)
await member.add_roles(autorole)
untold token
weary gale
#

i already have an event

untold token
#

I told them to do that

#

No

#

Wrong

slate swan
#

wait yeah it's wrong

untold token
#

Don't spoonfeed wrong code

#

and use listen

#

Its better than .event

slate swan
#

no?

untold token
#

It is?

slate swan
#

how?

untold token
#

.event overrides your default event

weary gale
#

wtf am i doing wrong

untold token
#

that means you can only have one event type

weary gale
#

i feel like monke

untold token
#

.listen() is an external event listener

visual island
#

any error?

weary gale
#

no

untold token
#

that is asynchronous and it doesnt block/ override the default events

visual island
#

try printing something to see if the event's triggered

untold token
#

and

slate swan
#

want me to fix the code?

untold token
#

!d discord.ext.commands.Bot.listen

unkempt canyonBOT
#

@listen(name=None)```
A decorator that registers another function as an external event listener. Basically this allows you to listen to multiple events from different places e.g. such as [`on_ready()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_ready "discord.on_ready")

The functions being listened to must be a [coroutine](https://docs.python.org/3/library/asyncio-task.html#coroutine "(in Python v3.9)").

Example...
untold token
weary gale
#

it didnt even trigger

untold token
slate swan
#
@bot.listen()
async def on_member_join(member):
    role = discord.utils.get(member.guild.roles, name='thisissupposedtobetheroleid')
    await member.add_roles(role)
untold token
#

Bruh why would put the ID on the name

slate swan
#

I stole it from my own code, AND YES IT WORKS

untold token
#

That's wrong too

slate swan
#

It works man

weary gale
#
from discord.ext import commands

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

bot = commands.Bot(intents = intents, command_prefix = ["$", "$"])

@bot.listen()
async def on_member_join(member):
    autorole = member.guild.get_role(ijustremovedtheidbecauseprivacy)
    await member.add_roles(autorole)
    print("AUTOROLE TEST")```
slate swan
#

And ID is sometimes better

#
import discord
from discord.ext import commands

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

bot = commands.Bot(intents = intents, command_prefix = ["$", "$"])

@bot.listen()
async def on_member_join(member):
    role = discord.utils.get(member.guild.roles, name='thisissupposedtobetheroleid')
    await member.add_roles(role)
    print("AUTOROLE TEST")
untold token
#
@bot.listen()
async def on_member_join(member: discord.Member):
    role = member.guild.get_role(ID)
    await member.add_roles(role)
#

How hard is it to do this

#

Its better and more accurate

slate swan
#

ok

#

...