#discord-bots

1 messages · Page 802 of 1

sick birch
#

!e

# see why this wouldn't work?
print(x)
x = 5
unkempt canyonBOT
#

@sick birch :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 2, in <module>
003 | NameError: name 'x' is not defined
sick birch
#

your variable has to come before when you use it

pallid mango
#
@client.event
async def on_member_update(before, after):
    guild = client.get_guild(932840827212931123)
    role = discord.utils.find(lambda r: r.name == 'promoter', guild.roles)
    if ".gg" in str(after.activity.name):
      await after.add_roles(role)
    if ".gg" not in str(after.status.name):
      await after.remove_roles(role)```
sick birch
#

perfect

pallid mango
#

yay !

sick birch
#

Though I think something might be wrong with the utils.find

#

Perhaps using guild.get_role(id)? It's more reliable

pallid mango
#

File "main.py", line 63, in on_member_update if ".gg" in str(after.activity.name): AttributeError: 'NoneType' object has no attribute 'name'

sick birch
#

But if you really want to use the name, the first argument is an iterable, the 2nd is an attribute

pallid mango
#

i get this error every now and then

sick birch
#

That could happen if the user doesn't have a status

pallid mango
#

id is better

sick birch
#

of course

#

that's why i'm suggesting use ID rather than name

pallid mango
#
@client.event
async def on_member_update(before, after):
    guild = client.get_guild(932840827212931123)
    role = guild.get_role(935258354689925150)
    if ".gg" in str(after.activity.name):
      await after.add_roles(role)
    if ".gg" not in str(after.status.name):
      await after.remove_roles(role)```
sick birch
#

awesome

pallid mango
#

yay

#

also

slate swan
#

@sick birch

#

🥺

sick birch
#

Yes

pallid mango
#
  @commands.command(help = 'Ban a member!')
  @commands.has_permissions(ban_members = True)
  async def ban(self, ctx, member : discord.Member = None, reason=None):
    if member == None:
      await ctx.reply("please mention a user")
    else:
      await member.ban(reason = reason)
    embed = discord.Embed(description= f"✅ **{member.display_name}#{member.discriminator} banned!**", color=discord.Color.green())
    await ctx.send(embed=embed)```
#

how do i ban by ID?

velvet tinsel
#

Robin helper be like

sick birch
#

If you have the ID you probably have the object

sick birch
#

At least the banning part

sick birch
pallid mango
#

but i cant ban unless they are in the server

sick birch
#

That's how banning works

pallid mango
#

carl bot bans when they arent?

sick birch
#

Oh you mean just adding someone to the banned list?

pallid mango
#

yes

velvet tinsel
sick birch
#

!d discord.Guild.ban

unkempt canyonBOT
#

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

Bans a user from the guild.

The user must meet the [`abc.Snowflake`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.Snowflake "discord.abc.Snowflake") abc.

You must have the [`ban_members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.ban_members "discord.Permissions.ban_members") permission to do this.
velvet tinsel
#

I'm gonna leave you to it

#

bye~

sick birch
#

Haha feel free to help though

velvet tinsel
#

before I even start typing you finish the sentence for me

sick birch
#

:P

#

Been doing this for a while haha

velvet tinsel
#

how am I supposed to

pallid mango
velvet tinsel
#

I'm a bit rusty at dpy rn lol

pallid mango
#

or would i have to make a separate command

sick birch
#

anyway @pallid mango discord.Guild.ban() takes a discord.abc.Snowflake

velvet tinsel
frozen patio
#

what is the problem here? the status wont show

sick birch
#

You can make your own like so:

mySnowflake = discord.Object(id)
velvet tinsel
sick birch
#

and pass that into ban(0

pallid mango
sick birch
final iron
#

😡

velvet tinsel
#

PEP8 regulator my guy

#

ima change my name rq

sick birch
final iron
#

I think you should actually watch these variable names though

frozen patio
#

this was working earlier

final iron
#

You're inadvertently teaching people bad practices

velvet tinsel
#

there we go

slate swan
slate swan
velvet tinsel
sick birch
# velvet tinsel whats snowflake

An ID, you can get the time it was created from it. Most things in discord are snowflakes: messages, channels, guilds, users, members, you name it. Hence why it's an ABC, an abstract base class. Most things in d.py subclass discord.abc.Snowflake in one way or another

slate swan
#

use the kwarg in commands.Bot

frozen patio
sick birch
velvet tinsel
#

thanks robin

sick birch
#

👍

slate swan
#

!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.
frozen patio
sick birch
#

Just beware clear won't work on all systems, either way it's not async so avoid using it

frozen patio
#

so change the code to what?

sick birch
#

And since on_ready can get called multiple times for no reason, it can clear your console for no reason which is bad if there are errors you haven't looked at yet

#

!d discord.Client

unkempt canyonBOT
#

class discord.Client(*, loop=None, **options)```
Represents a client connection that connects to Discord. This class is used to interact with the Discord WebSocket and API.

A number of options can be passed to the [`Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client").
frozen patio
pallid mango
#

works for me

sick birch
#

pass in the activity

#

Let's not spoonfeed them please

pallid mango
#

oh

#

my bad pimp

sick birch
#

it can also prevent your bot from fully connecting to the gateway, since you can get kicked before you even get the GUILD_CREATE events

#

in short: only thing you should do in on_ready() is print

frozen patio
#

hmm, im just trying to get this fixed to continue on an unmute command

sick birch
#

nothing else, no exceptions

pallid mango
#
  @commands.command(help = 'Ban a member!')
  @commands.has_permissions(ban_members = True)
  async def ban(self, ctx, member : discord.Member = None, reason=None):
    mySnowflake = discord.Object(id)
    if member == None:
      await ctx.reply("please mention a user")
    else:
      await member.ban(reason = reason)
    embed = discord.Embed(description= f"✅ **{member.display_name}#{member.discriminator} banned!**", color=discord.Color.green())
    await ctx.send(embed=embed)```
sick birch
sick birch
frozen patio
sick birch
#

keyword argument

#
bot = commands.Bot(..., activity=..., ...)
frozen patio
#

i am confused on what you want me to do

slim ibex
#

!args-kwargs

unkempt canyonBOT
#

*args and **kwargs

These special parameters allow functions to take arbitrary amounts of positional and keyword arguments. The names args and kwargs are purely convention, and could be named any other valid variable name. The special functionality comes from the single and double asterisks (*). If both are used in a function signature, *args must appear before **kwargs.

Single asterisk
*args will ingest an arbitrary amount of positional arguments, and store it in a tuple. If there are parameters after *args in the parameter list with no default value, they will become required keyword arguments by default.

Double asterisk
**kwargs will ingest an arbitrary amount of keyword arguments, and store it in a dictionary. There can be no additional parameters after **kwargs in the parameter list.

Use cases
Decorators (see !tags decorators)
Inheritance (overriding methods)
Future proofing (in the case of the first two bullet points, if the parameters change, your code won't break)
Flexibility (writing functions that behave like dict() or print())

See !tags positional-keyword for information about positional and keyword arguments

pallid mango
#
  @commands.command(help = 'Ban a member!')
  @commands.has_permissions(ban_members = True)
  async def ban(self, ctx, member : discord.Member = None, reason=None):
    mySnowflake = discord.Object()
    if member == None:
      await ctx.reply("please mention a user")
    else:
      await member.ban(reason = reason)
    embed = discord.Embed(description= f"✅ **{member.display_name}#{member.discriminator} banned!**", color=discord.Color.green())
    await ctx.send(embed=embed)```
final iron
sick birch
pallid mango
sick birch
frozen patio
sick birch
#

only you would know

final iron
pallid mango
final iron
#

You're manually making it a required argument

frozen patio
final iron
pallid mango
#

i followed tut on this ban command

pallid mango
#

just personalized it

pallid mango
#

slowmode is an ass

frozen patio
final iron
#

So no need to get the attributes

sick birch
#
bot = commands.Bot(..)
#

Should look like that

frozen patio
#

i use

#

bot = @bot.commands

sick birch
#

yes but you would need a bot instance for that to work

frozen patio
sick birch
#

yep, that's where you add the activity to

split merlin
#

Hi, I am trying to get access to all the tracks in a spotify playlist using spotipy python.
issue is that i only can extract the first 100 tracks from the playlist
when i searched around on how to get the full tracks, it seems that i have to authorize but i am using SpotifyClientCredentials with my client ID and client secret but i still get the first 100 only and the SpotifyOauth or whatever it was called requires a redirect_uri which i don't need, i kept searching for any documents or solutions and i found out that i can use playlist = spotify.playlist_tracks(playlist_url, offset=number, limit=number2) inside a while loop while increasing the offset number so i can get the next 100 and etc but all it does is keep repeating the first 100 songs till it exists the while loop
I am not sure if there is a way with this library and i am open to any recommendations, Thank you
also i see that playlist_tracks is being crossed out like playlist_tracks, idk why

sick birch
#

Not related to discord bots, you'd have better luck either in #python-discussion or claim yourself a help channel

split merlin
#

oooh okay

#

sorry and thanks

sick birch
#

No prob

pallid mango
#

okay

#

so can i clear this ban command up a lil bit

#
  @commands.command(help = 'Ban a member!')
  @commands.has_permissions(ban_members = True)
  async def ban(self, ctx, member : discord.Member = None, reason=None):
    mySnowflake = discord.Object()
    if member == None:
      await ctx.reply("please mention a user")
    else:
      await member.ban(reason = reason)
    embed = discord.Embed(description= f"✅ **{member.display_name}#{member.discriminator} banned!**", color=discord.Color.green())
    await ctx.send(embed=embed)```
#

pep8 said i have extra stuff

final iron
slate swan
#

how to take a message i send to my bot in dm so then bot sends it to a channel?

pallid mango
#

nobody can really see what u said, the bot deletes it fast enough

slate swan
#

but for example bot sends it to channel when users cant send messages

pallid mango
#

yea?

#

just make a repeat command

#

unless ur the user that cant send messages

slate swan
#

but do you know how do i take received DM message?

final iron
#

Commands should work in dms, no?

slate swan
#

do they?

#

@frozen patio thanks bro

final iron
slate swan
#

i owe you one

final iron
#

They should

frozen patio
final iron
#

!d discord.ext.commands.dm_only

unkempt canyonBOT
#

@discord.ext.commands.dm_only()```
A [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") that indicates this command must only be used in a DM context. Only private messages are allowed when using the command.

This check raises a special exception, [`PrivateMessageOnly`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.PrivateMessageOnly "discord.ext.commands.PrivateMessageOnly") that is inherited from [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure").

New in version 1.1.
slate swan
#

was it you that helped me

final iron
#

This restricts it to a dm only command

slate swan
#

😳

frozen patio
final iron
slate swan
#

?

#

oh its an emoji

#

external emoji

#

sick right?

#

i can give it to you in dms

#

no problem

#

._.

#

@final iron

final iron
#

Looks very cool

slate swan
#

can i get the pfp of the bot

pallid mango
#

dude i have never seen someone use nextcord before lmfaooo

#

no it’s not related to u

final iron
#

bot.user.avatar_url. bot.user.avatar.url if you're on 2.0

slate swan
#

idk if im on 2.0

pallid mango
#

just saying i was tryna help someone earlier and they were using discord.py code with nextcord

slate swan
#

i dont think so honestly

flat solstice
#

okay so every since i added py invites = await ctx.guild.invites() for inv in invites: if inv.code == invite.code: return invto my command it's just stopped responding completely and I'm not getting any errors . This is my code. I'm assuming I've structured my for and if statements wrong to get it stuckpy @commands.command(description = "Get some information about a invite.", usage = "inviteinfo", aliases = ["invitestats", "ii"],) async def inviteinfo(self, ctx, invite: discord.Invite): invites = await ctx.guild.invites() for inv in invites: if inv.code == invite.code: return inv embed = discord.Embed(title = f"Server invite: {invite.code}", description = f"Invite created <t:{int(inv.created_at.timestamp())}:R>", colour = ctx.author.colour, url = invite.url) embed.set_author(name = f"ID: {invite.id}", icon_url = invite.guild.icon_url) embed.add_field(name = "Inviter", value = f"{invite.inviter.mention}|{invite.inviter.mention}" if invite.inviter else "Unknown") embed.add_field(name = "Uses", value = f"{invite.uses}/{'Infinite' if invite.max_uses == 0 else invite.max_uses}", inline = True) embed.add_field(name = "Expires", value = f"<t:{int(invite.max_age.timestamp())}:R>", inline = True) embed.add_field(name = "Temporary", value = f"{invite.temporary}", inline = True) embed.add_field(name = "Revoked", value = f"{invite.revoked}", inline = True) embed.add_field(name = "Channel", value = f"{invite.channel.mention}", inline = True) await ctx.reply(embed = embed)

final iron
#

Try print(discord.__version__)

slate swan
#

kk

final iron
#

!d discord.Invite.code

unkempt canyonBOT
slate swan
#

im back to discord.py dev and i forgot too many things

slate swan
#

fuck

final iron
#

returning essentially kills your function

slate swan
#

forgot to remove ''

#

alright im on 1.7.3

final iron
#

So it would be avatar_url

slate swan
#

kk

flat solstice
# final iron `return`ing essentially kills your function

oh, i always get the function ending's mixed up, I'm trying to return inv bc I don't want to have to ident the embed (minor thing) but I still need to get inv out of the function so i cna use it in py embed = discord.Embed(title = f"Server invite: {invite.code}", description = f"Invite created <t:{int(inv.created_at.timestamp())}:R>", colour = ctx.author.colour, url = invite.url)

flat solstice
#

👍

slate swan
#

avatar_url isnt used

final iron
#

bot.user.avatar_url

slate swan
#

kk

final iron
#

bot.user is a discord.user.ClientUser object

flat solstice
final iron
#

!d discord.ext.commands.Bot.user

unkempt canyonBOT
final iron
#

!d discord.user.ClientUser

unkempt canyonBOT
#

class discord.ClientUser```
Represents your Discord user.

x == y Checks if two users are equal.

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

hash(x) Return the user’s hash.

str(x) Returns the user’s name with discriminator.
sick birch
unkempt canyonBOT
#
Nah.

No documentation found for the requested symbol.

slate swan
#

im soo proud of my son omg

sick birch
#

oof

final iron
#

You got it working

#

Nice

slate swan
#

im planning to make bots for fiverr, is that a good idea?

slate swan
final iron
scarlet aurora
#
@bot.command()
async def commands(ctx):
    embed = discord.Embed(
        title=f"Commands",
        description=f"""
>help (shows this command)
>quote
>hello
>cmds
>tictactoe (mention) (mention)
>tmg
>slap (mention)
>cf (coinflip)
""",
        set_thumbnail(url="./tmgmidvitelogonowords.png")
        colour=0x3D9AF2)

    await ctx.send(embed=embed)```
final iron
#

I doubt you'll get a lot of purchases

neat tartan
scarlet aurora
#
    ^
SyntaxError: positional argument follows keyword argument```
slate swan
#

im making a bot that makes bots

#

🧠

neat tartan
slate swan
#

make an nft bot and youll get orders in no time

slate swan
#

or else you can make a mass dm bot

final iron
#

!d discord.Embed.set_thumbnail

unkempt canyonBOT
#

set_thumbnail(*, url)```
Sets the thumbnail for the embed content.

This function returns the class instance to allow for fluent-style chaining.

Changed in version 1.4: Passing [`Empty`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed.Empty "discord.Embed.Empty") removes the thumbnail.
final iron
#

That's how you set the thumbnail

slate swan
scarlet aurora
slate swan
#

a website where people post things like "buy my service"

#

and then people buy it

flat solstice
# slate swan dont return and add 2 tabs indent so the code will be inside the if statement

already done following pep 8's advice,
now my next issue; py embed.add_field(name = "Expires", value = f"<t:{int(invite.max_age.timestamp())}:R>", inline = True)is producing py AttributeError: 'NoneType' object has no attribute 'timestamp'which I understand since max_age is How long the before the invite expires in seconds. A value of 0 indicates that it doesn’t expire., is there a way I can wrap this seconds value in timestamp markdown, I assume I'll need to convert it to epoch time first

scarlet aurora
slate swan
scarlet aurora
#

ofc u can

slate swan
#

yes

#

you can sell any service

final iron
slate swan
#

the only command i hate looking at is... help

#

how can i make it more sexy

neat tartan
slate swan
#

no

final iron
slate swan
#

ok wait ill try putting the bots icon

slate swan
#

maybe itll look 10x better

slate swan
slate swan
scarlet aurora
neat tartan
#

now isnt that fucking delightful to look at OMEGALUL

final iron
#

You use the set_thumbnail method on your instance of the Embed object

#

embed.set_thumbnail()

slate swan
#

looks bad

#

i need more reactions

#

and catergories and reverse the emojis

scarlet aurora
slate swan
final iron
#

!d discord.Embed.set_thumbnail

unkempt canyonBOT
#

set_thumbnail(*, url)```
Sets the thumbnail for the embed content.

This function returns the class instance to allow for fluent-style chaining.

Changed in version 1.4: Passing [`Empty`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed.Empty "discord.Embed.Empty") removes the thumbnail.
slate swan
#

looks dope

final iron
#

Check the docs out

slate swan
slate swan
#

@pallid mango I used 'if isinstance(message.channel, discord.DMChannel):' and it worked

#

rate this out of ten

pallid mango
#

wasnt even sure of what u needed ngl

pallid mango
slate swan
#

alr what can i change

pallid mango
#

i thought u just wanted a way to send messages as a bot

slate swan
#

yes

pallid mango
pallid mango
slate swan
#

do you know how to send given file as well?

#

or at least image

pallid mango
#

i simply do .repeat <message> and bot deletes message and resends itself

slate swan
#

also ill update the emojis

slate swan
pallid mango
slate swan
#

should probably make the emojis myself

#

1 n?

#

thats disgusting i want to 🤮

pallid mango
slate swan
#

its like saying

#

max's dictionarrry

final iron
slate swan
pallid mango
slate swan
#

kk

pallid mango
#

i was just recommending to the other person

final iron
#

Ah

slate swan
#

is this better?

frozen patio
#

whats the problem with this?

slate swan
#

how do i use bot.wait_for and a function to check if the reaction is pressed to then do something

#

in my case i want it to edit the embed

#

ping me

final iron
slate swan
#

customize it in font awesome

#

wait

#

the icons arent centered

#

now they are

#

i made it on pixlr

#

but u said font awesome afterwards

#

ill use fontawesome next

#

you download the svg and color it on a svg editor

#

ez

#

nice

final iron
# slate swan

I wouldn't suggest you hard code your help command

#

It's a very bad idea

slate swan
#

alright i need to use bot.wait_for and a function that checks if the reaction is pressed and if a certain emoji is pressed something happens

final iron
slate swan
#

can i still use the same embed formatting

#

and stuff

final iron
#

It will explain everything

slate swan
#

ill make it like this

final iron
#

If you want I guess

slate swan
#

stella subclasses help cmd 99%

#

nvm 100%

#

why do you guys make discord bots

#

just curious

final iron
#

It was my first project

slate swan
#

i make it for my server

slate swan
final iron
#

I enjoyed it

slate swan
#

i enjoyed copy pasting from youtubers

#

nice

slate swan
#

python is great

#

very simple

slim ibex
#

i don't do much python dev anymore, but i still help

final iron
#

@slate swan I want to try contibuting to your project. How would I setup your code to make sure its working without errors?

manic wing
#

which project is this?

final iron
#

twitter api wrapper

slate swan
#

cool

manic wing
#

what needs to be done for that

slate swan
#

which is used for most request

#

not all*

manic wing
#

okimii give me yours

slate swan
#

its like 118 chars

final iron
#

So akeno = AkenoClient("my token here")?

slate swan
slate swan
final iron
slate swan
final iron
#

I understand that

#

See, I wont be directly giving data to the government but they're free to get it

slate swan
#

then no lol

#

let me make a akeno server lol

final iron
slate swan
neat tartan
final iron
#

Always give it a try

#

I've never contributed to a project either

neat tartan
#

aight, ill need a bit of help getting everything for it set up

reef trail
#

can tasks.loop take a guild argument?

gaunt ice
#

gib example

compact ruin
#

Guys whats the best hosting platform for Discord Bots?

#

in your opinions?

slate swan
#

your computer 🙂

#

You should try heroku but I only recommend if you want free alternative

sick birch
#

A raspberry pi is also a very good choice, while it's a heavy initial investment, it can be a pretty decent host while your bot isn't insanely huge, but keep in mind it doesn't scale either

manic wing
#

ignore robin, he's only saying aws because he gets it free 😡

sick birch
#

Sure, personally I'm working on a project where we use multiple AWS services and it's very good

slate swan
#

lucky robin simping

compact ruin
#

lmao

slate swan
sick birch
#

Keep in mind though AWS is a bit more expensive than the others

#

But they also have a bunch of other services and they tie together easily inside the ecosystem

celest zinc
#

how do i add roles using my discord bot

slim ibex
#

!d discord.Member.add_roles

unkempt canyonBOT
#

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

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

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

whats atomic

#

and what does it mean

#

"*roles"

slim ibex
#

any number of role arguments

#

idk what atomic is

celest zinc
#

so like

#

roles ="test", reason= None, atomic=False

#

?

slim ibex
#

that’s not how it works

celest zinc
#

await add_roles(discord.Role,reason=None,atomic=False)

celest zinc
rustic onyx
#
yaml = YAML()
with open("./Config.yml", "r", encoding = "utf-8") as config_file:
    config = yaml.load(config_file)

class OpenInterest(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.openinterest_btc_5.start()

    @tasks.loop(seconds = 3000)
    async def openinterest_btc_5(self):

        openinterest_channel = await self.bot.fetch_channel(config["Channels"]["OpenInterest"])
        btc_coinalyze_link = config["CoinAlyze"]["BTC"]

        btc_5_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

        oi_btc_binance_api = "https:/fapi.binance.com//fapi/v1/openInterest?symbol=btcUSDT"
        json_btc_oi_5 = response = requests.get(oi_btc_binance_api)
        json_btc_oi_get_5 = json_btc_oi_5.json()
        btc_binance_oi_5 = float(json_btc_oi_get_5["openInterest"])
        del btc_5_list[0]
        btc_5_list.append(btc_binance_oi_5)

        result = (statistics.stdev(btc_5_list))

        embed = discord.Embed(
        title = "![btc](https://cdn.discordapp.com/emojis/892499835930939442.webp?size=128 "btc") Open Insterest Alert",
        description = f"Variation Detected ![alert](https://cdn.discordapp.com/emojis/939324083542302780.webp?size=128 "alert")!",
        color = config["Embed"]["Color"])
        embed.set_footer(text = config["Embed"]["FooterText"],
        icon_url = config["Embed"]["IconURL"])
        embed.add_field(name = "Open Interest Data", value = f"{result}", inline = False)
        await openinterest_channel.send(embed = embed)

def setup(bot):
    bot.add_cog(OpenInterest(bot))
    print("OpenInterest Cog: Logged")
``` So... I have this running but I think a file cannot be updated while running right??? Considering that, will this cog work? Thanks in advance 🙏
sick birch
#

There's no reason a file can't be updated while the bot's running, though you should use aiofiles since it's not blocking

silent portal
#

Hi, I have a task (loop) which repeats every 5 minutes.

However 1-2 days the task stops and I get this error:

[Errno 104] Connection reset by peer```
Every other task or command works fine but not this loop. Is there a way I can fix this?
rustic onyx
final iron
neat tartan
silent portal
rustic onyx
#

Have you tried at least? Are you having the same error?

rustic onyx
silent portal
rustic onyx
#

You are using an API?

#

Or something? Maybe that's the reason, you are being limited

sick birch
#

if so, for one consider using a data, but aiofiles is not blocking so consider using that instead

rustic onyx
#

nono just using that same script I send

#

everything in the same file

sick birch
#

it's opened, all the contents are read, then closed

rustic onyx
#

but its a task Shrugg

#

it should be repeating once it finishes

sick birch
#

the with open() is all outside

#

It's not writing because you actually have to dump the contents back into the yaml file

rustic onyx
#

Well then lemme send the full code I edited some parts before sending it here

sick birch
#

nono this is alright

#

i know what the issue is

#

yeah it reads all the contents of the file, stores it, then immediately closes it

#

so the file isn't open at all

rustic onyx
#

I should create a secondary python file where I append and delete and do all the stuff I want?

sick birch
#

the reason it's not showing up in the file is because you need to dump the contents back in

rustic onyx
#

1.- What's that
2.- How can I do it

🤣

sick birch
#

the config variable is just a copy

rustic onyx
#

never heard about dumping contents back in

sick birch
#

not the actual file itself

rustic onyx
#

but the problem isnt the config file

sick birch
#

then?

rustic onyx
#

the list is causing the problem I think

sick birch
#

what is the problem though

rustic onyx
#

I have the same format of file with the config outside the class and it works

compact ruin
#

Guys is there a way i could have someone send an image with a command then turn it into a link?

sick birch
#

right but what is the problem?

sick birch
compact ruin
#

Ty for giving my common sense back

sick birch
#

discord automatically turns it into an attachment

rustic onyx
#

I'm expecting the list to be updated every 3000 seconds and then send the stdev of the list in an embed

sick birch
#

there we go

rustic onyx
#

but thats not happening, nothing is happening basically

rustic onyx
#

btc_5_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

sick birch
#

odd it should be updating since it's just a variable

rustic onyx
#

its just not working, no traceback

sick birch
#

try printing the list

rustic onyx
#

idk why, I checked that its logging correctly, etc

rustic onyx
sick birch
#

print(btc_5_list) and see if it's different each time

rustic onyx
#

but its not even sending the stdev the first time, but ok I'll print it right now

#

not updating

#

and its not even sending the embed to the openinterest_channel

#

idk I give up 🤷‍♂️

final iron
cosmic dirge
#

lmao

manic wing
#

maybe async is just an idea

#

what is async

#

who is async

slate swan
#

i think caeden drank to much tea

manic wing
#

what is real

slate swan
#

👀

final iron
manic wing
#

its 3am

slate swan
slate swan
manic wing
#

true that

slate swan
pine crown
#

help\

pine crown
#
@client.slash_command(description="Set up a mod log channel.")
async def SetModLog(ctx, channelid):
  db = sqlite3.connect('channels.db')
  cursor = db.cursor()

  cursor.execute("INSERT INTO channels VALUES (?, ?)", (channelid, ctx.guild.id))
  db.commit()

why this thing not working

slate swan
#

    @commands.command(brief="Checks status of servers   being monitored", usage="status")
  #  while True:
   #   time.sleep(30)  
    async def status(self, ctx) -> None:
        """Returns an embed showing the status of each monitored server"""
      
        embed = embeds.Embed(
            title="**Estado De Los Servidoress**",description="Este es el estado actual de nuestros servidores, este mensaje se actualizará cada cierto tiempo." ,color=16711680 if self.currently_down else 65287
        )

        for i in get_servers():
            if i["address"] in self.currently_down:
                downtime = str(timedelta(seconds=self.currently_down[i["address"]]))
                embed.add_field(
                    name=f"{i['name']} ({i['type']})",
                    value=f":red_circle: Sin Conexión ({downtime})",
#value=f":red_circle: {i['address']} ({downtime})",
#value=f":red_circle: Oculto ({downtime})",
                    inline=True,
                )
            else:
                embed.add_field(
                    name=f"{i['name']} ({i['type']})",
                    value=f":green_circle: En Línea",
#value=f":green_circle: {i['address']}",
#value=f":green_circle: Oculto",
                  
                    inline=True,
                )
        msg = await ctx.fetch_message(939283098821087312)

        await msg.edit(embed=embed)
        # await ctx.send(embed=embed)

I have this code, its a command to monitor the status of some servers, what it does is that when I run the command a message updates with the status of each server and if it is online or offline it shows, that works.

The thing is that I want to make this, like a js setInterval, that i just run the command once and it automatically re-runs the command every 30 seconds, I've been searching for serInterval python codes but all of them weren't working.
PData

pine crown
pliant gulch
#

They are using parameterised statements

#

Pretty sure it would be sanitised

manic wing
#

channelid is not typehinted as anything?

pliant gulch
pine crown
#

how to fix

pliant gulch
#

Like, you won't be able to send a DROP TABLES statement

pine crown
#

oh

#

i must make it to integer?

manic wing
manic wing
pliant gulch
#

Mmm the parameterised statement means that it would be santised

#

You could exploit this command if they used f-strings instead

pine crown
#

ok

#
@client.slash_command(description="Set up a mod log channel.")
async def SetModLog(ctx, channelid):
  db = sqlite3.connect('channels.db')
  cursor = db.cursor()

  cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")

  cursor.execute("INSERT OR IGNORE INTO channels VALUES (?, ?)", (channelid, ctx.guild.id))
  db.commit()

this works?

final iron
#

Use aiosqlite

#

!pypi aiosqlite

unkempt canyonBOT
hushed galleon
#

yeah in terms of sql injection thats not a problem, but you are inserting strings into an integer field

final iron
#

sqlite3 is blocking

pine crown
final iron
pine crown
#

ok

hushed galleon
#

consider using a discord.TextChannel converter and accessing the id from that so dpy can verify that the given id is a valid channel

#

i.e. async def SetModLog(ctx, channel: discord.TextChannel):

pine crown
# final iron It's just sqlite3 with await's
db = sqlite3.connect('channels.db')
  cursor = db.cursor()

  cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")

  cursor.execute("INSERT OR IGNORE INTO channels VALUES (?, ?)", (channelid, ctx.guild.id))
  db.commit()

how to convert into aiosqlite

manic wing
#

dont create a new instance of db each time

pine crown
#

ok

#
@client.slash_command(description="Set up a mod log channel, this command needs to be sent in the channel you want the modlogs to be sent.")
async def SetModLog(ctx, channelid: disnake.TextChannel):
  db = sqlite3.connect('channels.db')
  cursor = db.cursor()

  cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")

  cursor.execute("INSERT OR IGNORE INTO channels VALUES (?, ?)", (channelid, ctx.guild.id))
  db.commit()

like this?

final iron
hushed galleon
# manic wing dont create a new instance of `db` each time

adding to this, you can add the db as a bot var and connect to it before running your bot, e.g. ```py
bot = MyBot()

async def main():
async with aiosqlite.connect('mybot.db') as db:
bot.db = db
await bot.start(TOKEN)

somewhere else

@bot.command()
async def mycommand(ctx):
cursor = await bot.db.execute('SELECT something FROM a_table')
row = await cursor.fetchone()

asyncio.run(main())```

final iron
pine crown
#

what is that

#

um

#

ok

pine crown
hushed galleon
#

sure, client.start() is basically the async version of client.run

pine crown
# hushed galleon sure, client.start() is basically the async version of client.run
@client.slash_command(description="Set up a mod log channel, this command needs to be sent in the channel you want the modlogs to be in.")
async def SetModLog(ctx, channelid: disnake.TextChannel):
    cursor = await client.db.execute('SELECT something FROM a_table')
    row = await cursor.fetchone()

this creates a table or i have to write the code

hushed galleon
#

you can create the table just before your bot starts, easier than having to create it anywhere your commands may need it

pine crown
#

ok

final iron
#

You might want to add a command that allows you to execute sql within discord

#

Makes your life so much easier

pine crown
#

does it have to be in the main()

final iron
#

Well async code has to be executed in a function

final iron
#

By putting it in a function?

#

I'm getting the feeling you havent learned python yet

#

I would highly recommend you do so

pine crown
#
async def main():
    async with aiosqlite.connect('channels.db') as db:
        client.db = db
        cursor = db.cursor()
        await client.start(token)
        cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")

like this

slate swan
#

sure, but you need to commit it as well

#

and dont use the async with method to bind it with the Bot

#
client.db = await aiosqlite.connect('database') 
``` is all you need
hushed galleon
#

iirc there's nothing wrong with using async with, at least it explicitly lets the connection get closed when the bot stops

slate swan
#

sure, but thats a quite inefficient way, and the connection will be lost as soon as the main function is completed

pine crown
#

ok

slate swan
#

i mentiond that in the next message

hushed galleon
#

i highly doubt its an "inefficient" way, and in their case both are equivalent

slate swan
#

not in the sense of connection, but they are doing something in 3 lines which can be done in a single one.

pine crown
#

ohh

#

i didnt see that

#

sorry

slate swan
#

and ofcourse, this

pine crown
# slate swan i mentiond that in the next message
@client.slash_command(description="Set up a mod log channel, this command needs to be sent in the channel you want the modlogs to be in.")
async def SetModLog(ctx, channelid: disnake.TextChannel):
    client.db = await aiosqlite.connect('channels.db')
    cursor = await client.db.cursor()
    cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")
    

like this?

hushed galleon
#

its only two lines, async with and client.db = db, of which both are equally as readable and isnt worth a debate over

pine crown
#

which waydo i do

hushed galleon
#

well you already typed it, leave it as that

#

oh wait you placed it inside your command

pine crown
#

i can remove it

slate swan
#

and the old one wont be closed either

pine crown
slate swan
#

then you would like using the async with method, and there's no need to use it as a botvar

#
@command()
async def my_cmd(..
   async with aiosqlite.connect() as db:
      # db is the Connection
      ...
   # connection gets closed as soon as your are outside the with statement```
this will close the connection as soon as your work is done
pine crown
#

ok

#

wat is @command

slate swan
#

take it as a reference.. ¯_(ツ)_/¯

pine crown
#

ok

pine crown
slate swan
#

yea, you could say that

pine crown
#

ok

pine crown
# slate swan yea, you could say that
@client.slash_command(description="Set up a mod log channel.")
async def SetModLog(ctx, Channelid: int):
    async with aiosqlite.connect('mybot.db') as db:
        client.db = db
        cursor = db.cursor()
        await client.start(token)
        cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")
```like this?
slate swan
#

why would you start the bot inside a command??

pine crown
#

oh ill remove that

#

i forgot

slate swan
#

yea it seems ok

pine crown
#

ok

#

cursor.commit?

slate swan
#

but make sure to commit it too

#

await db.commit()

pine crown
#

ok

slate swan
#

everytime you perform a "write" operation, you need to commit into the database

pine crown
#
cursor.execute("INSERT INTO channels VALUES(?, ?)", (ctx.guild.id, Channelid))

i also add this?

slate swan
#

depends on what you want to do,.

pine crown
#

yes

#

i have to create database file on my own?

pine crown
# slate swan depends on what you want to do,.
@client.slash_command(description="Set up a mod log channel.")
async def SetModLog(ctx, Channelid):
  async with aiosqlite.connect('channels.db') as db:
    client.db = db
    cursor = db.cursor()
    cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")
    cursor.execute("INSERT INTO channels VALUES(?, ?)", (ctx.guild.id, Channelid))
    await db.commit()

whyh when i run this command its not making a new table

slate swan
#

errors?

slate swan
#

how do you know that the table is not getting created.?

pine crown
#

i used the broswer

#

and opened the db file

slate swan
#

you need to reopen the database file after commiting.

pine crown
#

how to do thar

slate swan
#

in your browser

pine crown
#

yeah i did

#

i dont even think the code went thru

#
@client.slash_command(description="Set up a mod log channel.")
async def SetModLog(ctx, Channelid):
  async with aiosqlite.connect('channels.db') as db:
    client.db = db
    cursor = db.cursor()
    cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")
    cursor.execute("INSERT INTO channels VALUES(?, ?)", (ctx.guild.id, Channelid))
    await db.commit()
    print("done")

it doesnt print done

slate swan
#

add a print statement to check if the slash command gets executed or not

#

oh

#

did you use that command 🤨

pine crown
#

yes

slate swan
#

show

pine crown
final iron
#

You need to respond

slate swan
#

is that disnake? ¯_(ツ)_/¯

pine crown
#

yes

final iron
#

It should still be printing

pine crown
#

it didnt print

slate swan
#

oh get it

#

you didnt await the executes

pine crown
#

oh

final iron
#

He's using sqlite3

slate swan
#

no

pine crown
#

i changed to aiosqlite

final iron
#

Oh

pine crown
#
@client.slash_command(description="Set up a mod log channel.")
async def SetModLog(ctx, Channelid):
  async with aiosqlite.connect('channels.db') as db:
    client.db = db
    cursor = db.cursor()
    await cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")
    await cursor.execute("INSERT INTO channels VALUES(?, ?)", (ctx.guild.id, Channelid))
    await db.commit()
    print("done")
```everything has to be with await?
#

even the clinet.db

slate swan
#

await them all

#

not the client.db

pine crown
#

ok

maiden fable
#

👀

slate swan
#

also, why do you use client.db when you dont need a permanent connection

pine crown
#

idk

#

what hsould i do it as

slate swan
#

you dont need to do that

maiden fable
#

Hm u should open it once only yk

pine crown
#

ok

slate swan
#

unless you want to keep a connection established

pine crown
#

ok

#

it sitll didnt make thje table

west juniper
#

Gys help

slate swan
final iron
slate swan
west juniper
pine crown
# slate swan show your current code
@client.slash_command(description="Set up a mod log channel.")
async def SetModLog(ctx, Channelid):
  async with aiosqlite.connect('channels.db') as db:
    cursor = db.cursor()
    await cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")
    await cursor.execute("INSERT INTO channels VALUES(?, ?)", (ctx.guild.id, Channelid))
    await db.commit()
    print("done")
final iron
#

Confirm its not doing that

slate swan
#

and dont use f strings in sql 💀

pine crown
#

but theres no f string

final iron
west juniper
#

pls help

final iron
#

huh

night bear
final iron
#

Oh

slate swan
pine crown
#

hi

#

it stiull doesnt work

final iron
#

It's just freezing?

pine crown
#
@client.slash_command(description="Set up a mod log channel.")
async def SetModLog(ctx, Channelid):
  async with aiosqlite.connect('channels.db') as db:
    cursor = await db.cursor()
    await cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")
    await cursor.execute("INSERT INTO channels VALUES(?, ?)", (ctx.guild.id, Channelid))
    await db.commit()
    print("done")
#

doesnt create a table and doesnt priunt

final iron
#

You got an error handler eating errors?

pine crown
#

like ifinstance?

final iron
#

Yeah

pine crown
#
@client.event
async def on_slash_command_error(interaction, error):
  if isinstance(error, commands.MissingPermissions):
    embed=disnake.Embed(color=0xb30000, title="Error", description="You do not have the permission to use this command.")
    await interaction.send(embed=embed)
final iron
#

Add:

    else:
        traceback.print_exception(type(error), error, error.__traceback__)

To the end of that

#

Make sure to import traceback

pine crown
#

ok done

#

now wat

final iron
#

Try running the command again

#

Your error handler was eating errors

pine crown
#

Still no working\

final iron
#

Is there an error?

pine crown
#

no

final iron
#

Did you restart your bot?

pine crown
#

yes

#

do uw ant to see my full code

final iron
#

Yeah

pine crown
#

ok i will send in dm

final iron
#

No

#

!paste

unkempt canyonBOT
#

Pasting large amounts of code

If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

pine crown
#

but i dpnt wanna leak it

final iron
#

Leak what

pine crown
#

its a big code

final iron
pine crown
#

i send u link i n dm

final iron
#

No

#

Send the link in here

pine crown
#

but people will look it ):

final iron
#

Ok and?

pine crown
#

fine

final iron
#

You need to use len() on your bot instance

#

Not on the class itself

pine crown
#

dumb?

#

😮

final iron
#

len(bot.cogs)

#

bot is your instance of commands.Bot

#

Therefore you can access all your attributes and methods of the Bot class with bot

#

Show the code

#

You probably did the same thing as before

pine crown
#

is there error

#

in my code

final iron
#

It can be called multiple times

pine crown
#

where should i put it

final iron
#

The command should be working

slate swan
#

and if you make request it will disconnect you from the gateway

pine crown
final iron
#

Can we see the code?

slate swan
#

well you cant add a method to that kwarg

#

you probably did discord.Color.< color name> and forgot to add ()

slate swan
#

.random()

final iron
#

discord.Color.random()

slate swan
pine crown
#

hi

#
@client.slash_command(description="Set up a mod log channel.")
async def SetModLog(ctx, Channelid):
  async with aiosqlite.connect('channels.db') as db:
    cursor = await db.cursor()
    await cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")
    await cursor.execute("INSERT INTO channels VALUES(?, ?)", (ctx.guild.id, Channelid))
    await db.commit()
    print("done")

anyone know why it no work?

slate swan
#

because channelid needs to be an integer and you try to push a string into it

pine crown
#

ok

#
Channelid: int

like this?

slate swan
#

sure, but thats not how slash options work ig

pine crown
#

well waht should i put ti as

west juniper
#

anyone help

pine crown
pine crown
neat tartan
# west juniper anyone help

not related to the issue but you should put the bot token in a .env file and pull it from the file istead of having it open in the code

slate swan
pine crown
slate swan
#

ye.

pine crown
#

still doesnt work

#

why does python hate me lol

pine crown
pine crown
#

936246330286809101

boreal ravine
#

when are people actually gonna learn python properly before using discord.py

boreal ravine
final iron
#

Are you loading the cog?

#

So it's sending but not editing?

slate swan
#

¯_(ツ)_/¯

final iron
#

You got an error handler eating up errors?

nova summit
#

Hi

#

Can anyone tell me how to make a command which will unban everyone in discord ban list of server

slate swan
unkempt canyonBOT
#

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

Unbans this member. Equivalent to [`Guild.unban()`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild.unban "discord.Guild.unban").
slate swan
#

!d discord.Guild.bans

unkempt canyonBOT
#

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

Retrieves all the users that are banned from the guild as a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of [`BanEntry`](https://discordpy.readthedocs.io/en/master/api.html#discord.BanEntry "discord.BanEntry").

You must have the [`ban_members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.ban_members "discord.Permissions.ban_members") permission to get this information.
slate swan
#

yep

nova summit
#

Hello?

#

;-;

#

Idk about cogs sorry

neat tartan
#

has nothing to do with cogs

#

worry maybe, ill try

neat tartan
#

add a print statement and see if its even calling the code or getting to certain parts of it

patent hare
#

Hey guys I am trying to build a discord bot and want to ask you all can I build a discord bot for my friends server like so far I have noticed that one have to set up a bot using discord settings in their own server but how can I build a bot for someone else's server?

timid wagon
#

a) Messages have a created_at attribute, not a timestamp.
b) The datetime object you get from that will not have anything called total_seconds(). You have to look for the seconds parameter.

patent hare
#

There should be authorization issues in someone else's server

timid wagon
patent hare
timid wagon
#

No, only people who've been given a role with the permission

boreal ravine
patent hare
timid wagon
patent hare
neat tartan
timid wagon
patent hare
neat tartan
#

dont use repl

timid wagon
#

Yeah well, avoid using repl

slate swan
neat tartan
# timid wagon oh boy

i think repl is the bad one. there is 1 common one people always ask or say they use thats bad

patent hare
#

Then how will the bot remain active if I will close my computer

boreal ravine
#

use a host/vps

neat tartan
#

put it on a VPS

slate swan
timid wagon
#

Do we have a tag for hosting here?

boreal ravine
patent hare
timid wagon
patent hare
#

First of all I will have to learn asynchronous programming

boreal ravine
maiden fable
maiden fable
boreal ravine
maiden fable
#

VPS

boreal ravine
#

!source

unkempt canyonBOT
nova summit
#

@client.command(pass_context=True)
async def unbanall(ctx):
	guild=ctx.message.guild
	ban_list=await client.get_bans(guild)
	await client.say('Unbanning {} members'.format(len(ban_list)))
	for member in ban_list:
		await client.unban(guild,member)
   

Why it doesnt unban everyone in ban list?

boreal ravine
#

why copy code

visual island
#

old code

nova summit
#

Then

boreal ravine
#

very old

nova summit
#

What to do -_-

slate swan
boreal ravine
#

Client.unbanisn't even a thinganymore

nova summit
#

Lol

timid wagon
#

Use the methods on ctx.guild.

#

These methods don't even exist in 2.0

maiden fable
#

@timid wagon go work on the guide

boreal ravine
nova summit
#

Then how to unban everyone in ban list

slate swan
#

I'm rn hosting my bot on Heroku bot the ping is high can anyone suggest me any other free hosting sites like heroku?

nova summit
#

😩

#

There are so many

timid wagon
boreal ravine
maiden fable
timid wagon
#

I'll work on the guide when I want to. Forcing me to create content won't get you anywhere

maiden fable
#

Rip

nova summit
maiden fable
unkempt canyonBOT
#

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

Retrieves all the users that are banned from the guild as a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of [`BanEntry`](https://discordpy.readthedocs.io/en/master/api.html#discord.BanEntry "discord.BanEntry").

You must have the [`ban_members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.ban_members "discord.Permissions.ban_members") permission to get this information.
boreal ravine
nova summit
nova summit
#

😁

timid wagon
#

@nova summit are you using dpy or one of the forks?

nova summit
slate swan
timid wagon
#

That didn't really answer my question

boreal ravine
maiden fable
#

I don't really think so 👀

timid wagon
#

I could link the guide for disnake kappa

maiden fable
#

U serious? 😐

timid wagon
#

Would clear a majority of the doubts, so yeah

maiden fable
#

Facts, but imagine him showing not defined error on the name disnake 👀

#

Would be fun ngl

timid wagon
nova summit
#

Like this?

nova summit
#

Then?

#

@maiden fable

maiden fable
#

Bro, bans() is a discord.Guild class method

nova summit
#

p

#

Then how to do it

#

Help

#
🥺
maiden fable
#
bans = await ctx.guild.bans()
for ban in bans:
    await ctx.guild.unban(ban.user)
#

!d discord.BanEntry

unkempt canyonBOT
#

class discord.BanEntry```
A namedtuple which represents a ban returned from [`bans()`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild.bans "discord.Guild.bans").
nova summit
#
@client.command() 
async def unbanall(ctx,member:discord.Member=None):
bans = await ctx.guild.bans()
for ban in bans:
    await ctx.guild.unban(ban.user) 
 

Like this?

maiden fable
#

yes, fix the indent BTW

nova summit
#

Thanks ❤

maiden fable
#

What u wanna do?

#

Ah

#

!d discord.Message.created_at

unkempt canyonBOT
maiden fable
#

Lemme show u

west juniper
#

can anyone explain how can i fix this error

maiden fable
#

So u gotta do (...).seconds

#

Instead of total_seconds()

maiden fable
west juniper
maiden fable
#

!d discord.Intents.reactions

unkempt canyonBOT
west juniper
#

@maiden fable

maiden fable
#

intents bruv

west juniper
maiden fable
west juniper
#

ok wait

west juniper
maiden fable
#

intents=discord.Intents.reactions()

west juniper
#

only problem is when i react to the message it did not show the winner

boreal ravine
maiden fable
#

Hmm

west juniper
boreal ravine
#

<t:2828828>

west juniper
heavy folio
#

!d discord.utils.format_dt

unkempt canyonBOT
#

discord.utils.format_dt(dt, /, style=None)```
A helper function to format a [`datetime.datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime "(in Python v3.9)") for presentation within Discord.

This allows for a locale-independent way of presenting data using Discord specific Markdown...
heavy folio
#

requires 2.0

exotic patrol
#

how do I add certain limit to snipe command?

pine crown
#

anyone can help me?

#
@client.slash_command(description="Set up a mod log channel.")
async def SetModLog(ctx, Channelid: int):
  async with aiosqlite.connect('channels.db') as db:
    cursor = await db.cursor()
    await cursor.execute("CREATE TABLE IF NOT EXISTS channels(guildid INTEGER, channelid INTEGER)")
    await cursor.execute("INSERT INTO channels VALUES(?, ?)", (ctx.guild.id, Channelid))
    await db.commit()
    print("done")
#

why does it not work

#

im using aiosqlite

velvet tinsel
#

how does it not work?

#

please specify

nova summit
#

Hello

#

Can anyone give discord py Server link

small igloo
#

ok, so i have a sql database, i get the id from it, and i get "('828182019841327115',)" as result, but i just want to extract the id, any idea how?

small igloo
pine crown
timid wagon
small igloo
timid wagon
timid wagon
timid wagon
timid wagon
#

Via index values?

small igloo
#

??

timid wagon
#
tuple = (1, 2, 3)
variable = tuple[0] # Gives '1'```
timid wagon
#

If you don't know how tuples work, you'll need to refer to basic Python

tender estuary
timid wagon
#

Go to an off-topic channel, thanks

small igloo
#

E

@bot.command()
async def whatUser(ctx):
    id = ctx.author.id
    if id == 828182019841327115:
        em = discord.Embed(title="players", description="players", colour=ctx.author.color)
        # await ctx.send(embed=em)
        l = database.length()
        for i in range (int(l)):
            s = database.get(i)
            user = await bot.fetch_user(s)
            o = user.display_name
            em.add_field(name=o, value=":shrug:", inline=False)
        await ctx.send(embed=em)
def length():
    cur.execute("SELECT COUNT(*) FROM users_data")
    s = cur.fetchone()
    return s

def get(index):
    cur.execute("SELECT NAME FROM users_data LIMIT 1 OFFSET ?",(index,))
    n = cur.fetchone()
    return n[0]

error:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'tuple'
slate swan
#

intents are not working for me too

#

a discord update broke it i think it used to work fine before they made this intent update

small igloo
#

hi okimi

slate swan
small igloo
west juniper
#

what is thecommand to role any member using bot?

slate swan
#

pardon?

#

dont you doubt me since i tried implementing intents on member_join

#

and member_remove

slate swan
#

despite importing the right intents it dosent works

#

yeah i doubt that show me your vars

slate swan
unkempt canyonBOT
#

@slate swan :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 2, in <module>
003 | TypeError: int() argument must be a string, a bytes-like object or a real number, not 'tuple'
pine crown
#

ok

quick gust
#

#bot-commands and thats not how you eval @pine crown

slate swan
#

eval only executes python code lol

pine crown
#

hi

slate swan
#

why wouldnt it work in all servers?

pine crown
#
@commands.has_permissions(administrator=True)
@client.slash_command(description="Set up the mod logs channel.")
async def setmodlog(ctx, modlogchannelid, YourUser: disnake.Member):
  with open(f"{YourUser.guild.name}.txt", mode="a") as temp:
    pass
  with open(f"{YourUser.guild.name}.txt", mode="w") as file:
    file.write(modlogchannelid)
  embed=disnake.Embed(color=0x00d60e, title="Mod Log Channel Set", description=f"Mod log channel set to {modlogchannelid}.")
  await ctx.send(embed=embed)
```would this work
slate swan
pine crown
#

idk why but my file the indents are smaller

slate swan
#

in discord it looks like it only has 2 spaces for a level

#

which it should be 4

#

for each level

pine crown
#

in my code is like that

#

but still works

slate swan
#

great

pine crown
#

idk why my code like that

slate swan
#

and i dont recommend making a file for each user

#

just use a db

pine crown
#

i changed to files becuase even though my db code is correct its not even working

pine crown
#

so i gave up on that

#

did u get github copilot

quick gust
#

there's definitely a problem if it isnt working, it cant be correct and not work

slate swan
quick gust
#

or joking?

slate swan
#

im not

pine crown
#

wtf

quick gust
pine crown
#

how o u not know

quick gust
#

we were talking about it yesterday okimii

pine crown
#

?

slate swan
#

suggesting whole lines or entire functions for you. just why

#

just do it yourself lol

pine crown
#

for beginers

#

but still its cool that they could code that

quick gust
pine crown
#

ok

#

why is my bot so trash

#

ugh

#

its takking so long just to update

slate swan
#

¯_(ツ)_/¯

quick gust
#

I just use it when im stuck on something

pine crown
#

idk how to use dtabase cuz its

slate swan
quick gust
#

it saves time aswell

quick gust
slate swan
pine crown
#

bruh]

quick gust
#

weird guy

slate swan
#

no more like work hard guy and not lazy beginner

#

you learn from your mistakes lol

pine crown
#

ughh

#

why my bot like this

quick gust
slate swan
#

what about it