#discord-bots

1 messages ยท Page 971 of 1

hasty chasm
#

@primal fox so is there any difference from using the intents from how discord bots used to work

primal fox
hasty chasm
#

yeah i read that but it seems like extra work to do the same thing

blissful sparrow
#

define it how exactly?

spice adder
#

Can you specify a guild on async def kick?

primal fox
blissful sparrow
primal fox
spice adder
#

Yes, I'm trying to have it kick the user from another server on_member_ban

blissful sparrow
primal fox
#

sorry, I assumed you would use your brain a little lol

#

you need to use the ID of the guild

#

why would a blank ID work?

blissful sparrow
hasty chasm
#

@primal fox it still didnt work do i have to add the extra lines of code in all my cogs or just the main file

blissful sparrow
#

wouldnt I be able to get the bot to fetch it and store it into id tho?

primal fox
hasty chasm
#

i did

#

but do i need to pass the intents in all of my cogs in the files

primal fox
primal fox
hasty chasm
#

ok it didnt work then

#

it only checks itself

primal fox
#

show your code where you passed it in

#

only way anyone can help you

hasty chasm
#
2022-04-12T00:14:54.565638+00:00 app[worker.1]: gerald#2492

this is the only line it gives

#

which is it returning it checked itself

primal fox
#

again, show the code where you create the intents and pass them to your bot

#

feel free to use a pastebin

hasty chasm
#
  @commands.command()
    @commands.has_role(950613237739708476)
    async def game_s(self,ctx):
        guild = ctx.message.author.guild
        Signed_up = ctx.guild.get_role(950611405986480208)
        channel = self.bot.get_channel(950613102100086854)
        if ctx.message.channel.id == 950613102100086854:
            for member in ctx.guild.members:
                print(member)
                if Signed_up in member.roles:
                    print(member)
                    await member.remove_roles(Signed_up)
                    await member.add_roles(ctx.guild.get_role(950611491101483089))
            await self.bot.get_channel(950614806702985296).send('The game has started <@&950611491101483089>')            
        elif ctx.message.channel.id != 950613102100086854:
            await ctx.send(f'{channel.mention}')
#

it skips the loop on

if Signed_up in member.roles:
primal fox
#

? that's not what I'm talking about

#
 intents.members = True

where is your code for this?

hasty chasm
#

its in the main file

#

this code is in a cog

primal fox
#

I'm asking to see that code

hasty chasm
#
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
import datetime
import emoji
import os
import random
client = discord.Client()
bot = commands.Bot(command_prefix = "$")
bot.remove_command("help")
intents = discord.Intents.default()
intents.members = True
#

that?

primal fox
#

as the docs said, you need to pass the intents to the bot when you create it. what you're doing is creating the bot, then the intents, and never passing them in, so they are lost forever

#

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

frozen patio
#

Yea

hasty chasm
#

ahhh ok sorry its been a while since i had to read up on the wiki

#

thanks

frozen patio
#

Why do you have to import Bot

primal fox
#

also remove client = discord.Client()

hasty chasm
primal fox
#

you really just need from discord.ext import commands

hasty chasm
#

i use it later on i see

#
@bot.event
async def on_ready():
    print("Im online")
    Bot.wait_until_ready
    client.wait_until_ready
    game = discord.Game("with your feelings")
    guild = bot.get_guild(950610895371915294)
    await bot.change_presence(status=discord.Status.online, activity=game)
extenstions = ['events','fun','help','levels','stats','In_game_roles','role_management','game_shift']
if __name__ == '__main__':
    for extension in extenstions:
        try:
            bot.load_extension(extension)
            print(extension)
        except Exception as error:
            print(error)
bot.run(os.environ['token'])
primal fox
#

discord.Client is a parent class of commands.Bot; you don't need it

frozen patio
#

Not really

#

When you import commands

#

It comes in that ๐Ÿ˜

primal fox
#

focus on one problem at a time; you could definitely clean your code up

frozen patio
#

Yea

#

I have errors of my own ๐Ÿคฃ

hasty chasm
#

yeah i def could but i never access this file and its never caused a problem

#

if i work on code i just make a new cog and add it to extensions and problem solve in the new cog

#

and to make yall more disappointed i use heroku to host it all

primal fox
#

most people who can't self host do that

frozen patio
#

I use pterodactyl

hasty chasm
#

how many hours do you get for free there @frozen patio

frozen patio
#

You need to install it all

#

Takes like 5 hours

hasty chasm
#

@primal foxyour a god man i wouldve never got this done without your help

slate swan
#

petrodacyl is not a host, it's a panel gui for hosting services

frozen patio
#

I host on there

sick birch
slate swan
#

literally every free hosting services uses it for their gui.....

#

That doesn't make it a host.

frozen patio
#

Anyways can someone PLEASE help me with this?

primal fox
sick birch
#

Error kind of says it

#

I'm guessing answers is a list with 0 or 1 items

sick birch
#

You can't get index 1 of an item with 0 or 1 items

#

since index 1 is the 2nd item

frozen patio
#

Yea

frozen patio
sick birch
#

I'm guessing you didn't add anything to the list then

frozen patio
#

No, because the answers you enter yourself

#

Like the time, channel, and what is being gaven away

sick birch
frozen patio
sick birch
#

That part isn't where it's pushing to the list

#

So I can't really tell if there's something wrong with it

frozen patio
#

Hmm

#

The command runs

#

Its the answers part

sick birch
#

Yeah

#

Your code isn't pushing to the list properly, as I said

frozen patio
#

Yeahh

#

Lemme go through here and look

frozen patio
blissful sparrow
#

ignore indentation vsc cant copy to clipboard properly

frozen patio
#

You have the 2nd decorator indented ๐Ÿ˜

#

Oh

#

Mk

blissful sparrow
#

Lol

#

someone said I couldnt do that hence why I removed the .bot

sick birch
frozen patio
sick birch
#

oh this

#

had to scroll up a bit

frozen patio
#

Ye that is it

muted dagger
#

thx so much man

blissful sparrow
#

nvm it worked lmfao, but it didnt leave the guild with id I set lmfao

sick birch
#

@frozen patio why not send each message and wait for each response?

blissful sparrow
#

but yes its a cog

frozen patio
sick birch
#
for question in questions:
  await ctx.send(...)
  answer = await bot.wait_for(...)
  answers.append(answer)
frozen patio
sick birch
#

I know, I'm suggesting that

#

It might help fix the issue

#

Since you're taking it one at a time instead of everything at once

#

Because as of right now, your wait_for only waits for the first message

sick birch
#

You either have to copy paste that line twice more or use the method I suggested

frozen patio
#

I do not think it being in an else statement affects it

sick birch
#

No, it doesn't

#

The fact that you're only calling it once, however, does

frozen patio
sick birch
#

wait_for

frozen patio
#

I have that line in 3 times now

sick birch
#

You either have to:

a1 = bot.wait_for(...)
a2 = bot.wait_for(...)
a3 = bot.wait_for(...)
answers.append(a1)
answers.append(a2)
answers.append(a3)

or, use my method:

for question in questions:
  await ctx.send(...)
  answer = await bot.wait_for(...)
  answers.append(answer)
frozen patio
#

i got this error:

sick birch
#

Yeah you're referencing c_id outside the try block

#

If it's inside a try block, it has a chance to not be defined

#

!e

try:
  x = 5/0
except:
  print("Oops, something went wrong :(")
print(x)
unkempt canyonBOT
#

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

001 | Oops, something went wrong :(
002 | Traceback (most recent call last):
003 |   File "<string>", line 5, in <module>
004 | NameError: name 'x' is not defined
slate swan
#

Define it outside then change it in

#

Maybe

sick birch
slate swan
#

..

sick birch
#

Python also doesn't let you allocate memory to them, but not give them a value like Java might:

String myString;
myString = "hello, world!";
frozen patio
#

I did have to move it up so it would be defined ig

sick birch
#

I know, you're defining it inside, but you're accessing it outside

frozen patio
#

Okay so put it in the try function?

sick birch
#

Yes

slate swan
#

Lol

lucid bison
#

anyone know how to get the channel id out of hikari.GuildMessageCreateEvent?

#

so i can send a message without the ctx context

maiden fable
maiden fable
lucid bison
#

one sec i think i got it

#

YES

#

ok i figured out prefix commands

frozen patio
#

Wdym???

blissful sparrow
#
@commands.command()
    @commands.is_owner()
    async def leave(self,ctx, guild=None):
        if guild is None:
            id = ctx.guild.id 
            guild = self.bot.get_guild(id)
            await guild.leave()
            print(f"Successfully left guild: {guild.name}")
        else:
            id = guild.guild.id
            guild = self.bot.get_guild(id)
            await guild.leave()
            print(f"Successfully left guild: {guild.name}")

Ok so the bot leaves the guild it currently is in but when I pass the guild param, it will still leave the guild its in and not the guild with the id i passed in the param

#

when i modify code to be:

@commands.command()
    @commands.is_owner()
    async def leave(self,ctx, guild=None):
        if guild is None:
            id = ctx.guild.id 
            guild = self.bot.get_guild(id)
            await guild.leave()
            print(f"Successfully left guild: {guild.name}")
        else:
            id = guild.guild.id
            guild = self.bot.get_guild(id)
            await guild.leave()
            print(f"Successfully left guild: {guild.name}")

https://caught-lackin-in-8k-by-cyberghost.cf/evxUKP40

You wasted 397.09 KB of space!

Caught lacking on Apr 12, 2022, 1:19 AM

#

ignore indents again cos vsc problems

slate swan
lucid bison
#

please explain

#

@slate swan

slate swan
#
# fetch method
channel = await event.message.fetch_channel()
# get method
c_id = event.message.channel_id
channel = bot.cache.get_guild_channel(c_id)
#

or if you're using lightbulb and have a context then ```
channel = ctx.get_channel()

lucid bison
#

ok lemme test

#

OMG TYSM

#

FINALLY

unkempt canyonBOT
#

Hey @muted dagger!

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

muted dagger
#

@slate swan what do you think of this?

slate swan
#

cool enough, some points
line 3 import discord, useless import

muted dagger
#

@bot.command()
@lightbulb.command("ping", "See Akuma's latency.", auto_defer=True)
@lightbulb.implements(lightbulb.SlashCommand)
async def ping(ctx: lightbulb.Context) -> None:
embed=hikari.Embed(title=f"My ping is {bot.heartbeat_latency * 1_000:.0f} ms.", color=0x6100FF)
await ctx.respond(embed=embed)

muted dagger
slate swan
#
@bot.command()
@lightbulb.add_checks(lightbulb.owner_only)
@lightbulb.option("text", "Text to repeat")
@lightbulb.command("echo", "Repeats the user's input")``` make the `text` option a required one so the command actually serves it purpose
#
@lightbulb.option("text", "Text to repeat", required=True)```
#

other things seems fine ๐Ÿ‘Œ

muted dagger
#

โœ…

muted dagger
slate swan
#

makes sense then, good job!

#

you can now try using plugins, they are like cogs in discord.py but a lot easier

muted dagger
#

thanks man, any ideas on how to make a ban command? im not familiar with events other than hikari.GuildMessageCreateEvent

lucid bison
#

maybe image.read()?

#

idk

slate swan
# muted dagger yo what are those

basically, you can have a single main file only with your bot defination and you have your commands and events in other files ```py

main.py

import lightbulb as lb

bot = lb.BotApp(prefix="", token="")
bot.load_extensions("other_file")
bot.run()

other_file.py

import lightbulb as lb

plugin = lb.Plugin(name="some commands", description="my first plugin")

@plugin.command
@lb.command("name", "desc")
@lb.implements(...)
async def command(ctx):
...

def load(bot):
bot.add_plugin(plugin)

muted dagger
#

file

slate swan
#

well thats helpful when you make a big bot, or need to make command categories

muted dagger
#

?

slate swan
#

try using discord.File("path") or utilise BytesIO

muted dagger
#

is there a website for examples in this stuff?

slate swan
#

take a hikari.Member/User type argument from the user as an option

astral anchor
#

guys is this a thing in python: x = not x

muted dagger
#

sadly

astral anchor
#

how is x = !x then done in python?

slate swan
muted dagger
unkempt canyonBOT
#

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

True
slate swan
#

its !=

astral anchor
#

no but like assign the exact opposite to it

muted dagger
lucid bison
#

!e x = x != True

muted dagger
lucid bison
#

!e x = False; x = x != True

astral anchor
#

ah my bad yes i meant
bool x = true
x = !x results in false

slate swan
muted dagger
#

thanks

lucid bison
#

!e x = False; x = x != True; print(x)

slate swan
lucid bison
#

use x = x != True

astral anchor
#

LMAO

#

that looks terrible

#

so x = not x is absolutely not possible

slate swan
#

if its a bool, its possible

astral anchor
#

ah ok thank u

slate swan
#

!e py a = True print(not a)

unkempt canyonBOT
#

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

False
astral anchor
#

the jjk movie was so good btw

slate swan
#

ikr

muted dagger
#

Traceback (most recent call last):
File "c:\Users\zgrew\OneDrive - Brisbane Catholic Education\Documents\Python\bot.py", line 5, in <module>
bot = lightbulb.BotApp(
AttributeError: module 'lightbulb' has no attribute 'BotApp'

#

@slate swan

blissful sparrow
#

whats the right way to see if the @commands.check_any() has passed true at least once?

nova bear
#

is it possible to make someone get a role if they answer the question that has a part of a text that i select, ex
!verify

user: something@gmail.com and if it has @ gmail.com in it it will give them a role?

slate swan
muted dagger
#

dont worry, fixed

#

i was messing with lightbulb files

#

ee

sick birch
lucid bison
#

how do you get attached files with hikari and attach files to a message?

nova bear
sick birch
#

Probably after your wait_for

nova bear
#

can i have an example?

#

and how could i make the rest of the message disband after if gmail isnt in the text

#

i want it to go after that and disband before checking info

sick birch
#
m = await bot.wait_for(...)
if "@gmail.com" in m.content:
  # give user role
else:
  return # "disbands" the rest of the code
nova bear
#

can i just shove that in after the part for email

sick birch
#

Yeah it just has to be after your wait_for

blissful sparrow
#
@commands.command()
@commands.is_owner()
async def leave(self,ctx, guild=None):
        if guild is None:
            id = ctx.guild.id 
            guild = self.bot.get_guild(id)
            await guild.leave()
            print(f"Successfully left guild: {guild.name}")
        else:
            id = guild.guild.id()
            guild = self.bot.get_guild(id)
            await guild.leave()
            print(f"Successfully left guild: {guild.name}")

This makes the bot leave if no guild id is given but will spit out Command raised an exception: AttributeError: 'str' object has no attribute 'guild' when I use an id, not sure where I've gone wrong here

nova bear
#

i dont have a waitfor

sick birch
#

Then how are you getting a user's answer?

nova bear
#

thats what i was going to ask next

sick birch
#

Ah, well you have your answer to that then

nova bear
#

i have it like this so far

slate swan
#

bad indentation

sick birch
# nova bear

Fix the indents, and also pass in the proper arguments to wait_for

#

!d discord.Client.wait_for see here for more information

unkempt canyonBOT
#

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

Waits for a WebSocket event to be dispatched.

This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way.

The `timeout` parameter is passed onto [`asyncio.wait_for()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for "(in Python v3.10)"). By default, it does not timeout. Note that this does propagate the [`asyncio.TimeoutError`](https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.TimeoutError "(in Python v3.10)") for you in case of timeout and is provided for ease of use.

In case the event returns multiple arguments, a [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.10)") containing those arguments is returned instead. Please check the [documentation](https://discordpy.readthedocs.io/en/master/api.html#discord-api-events) for a list of events and their parameters.

This function returns the **first event that meets the requirements**...
nova bear
#

im a bit confused

sick birch
#

I'm more than happy to explain, ask away

nova bear
#

alright

spring flax
#

I just have one question, are you ony going to be using that bot?

nova bear
#

i want to know how to make it so that if you respond to the question A PART of the text it will continue the rest of the text that will lead to you getting the role

spring flax
#

Yes

sick birch
#

Right, so we have this part:

m = await bot.wait_for(...)
``` yes?
#

It waits for the user's message, and stores said message in variable m

#

From there, you can access m.content, and check to see if @gmail.com is in that content

frozen patio
#

What? This honestly makes no sense, my serverinfo command is similiar to this.

nova bear
#

thats what i have so far

nova bear
# spring flax Yes

im going to be using it to check usernames and things, this is just a general example

sick birch
#

So far so good, make sure you indent it properly and fill in what's supposed to go in wait_for according to the documentation

#

Also time.sleep() is blocking

nova bear
#

where would i add the wait_for

sick birch
#

And with 15 second sleepers you're bound to forget to HEARTBEAT to the gateway and get yourself kicked off the socket

nova bear
#

well, i wanted to make it so you have 15 seconds to respond, if you respond earlier it will delete and start the other process\

sick birch
#

That's why timeout exists on wait_for

blissful sparrow
spring flax
#

Because if others would use that command, i don't think everyone would want to verify with their email address sending in publicly (this isn't anything wrong with the code, just my thoughts on the purpose)

sick birch
#

The docs page has a few examples for you to look at

sick birch
nova bear
sick birch
nova bear
#

I get that we are using it to wait for the user response

sick birch
#

Right, and you understand what this bit does:

m = await bot.wait_for(...)

specifically m?

blissful sparrow
sick birch
#

Your bot waits for a message, then stores that message object within m for you to access

blissful sparrow
#

I thought it would pass it from the parameter guild=None if I gave the optional parameter

frozen patio
# sick birch Can you send the full traceback?
Traceback (most recent call last):
  File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 168, in wrapped
    ret = await coro(*args, **kwargs)
  File "c:\Users\Student\Desktop\Lofi-Chill Rewrite\main.py", line 548, in userinfo
    await ctx.reply(embed=embed)
  File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\context.py", line 400, in reply
    return await self.message.reply(content, **kwargs)
  File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\message.py", line 1613, in reply
    return await self.channel.send(content, reference=self, **kwargs)
  File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\abc.py", line 1418, in send
    data = await state.http.send_message(
  File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\http.py", line 337, in request
    raise HTTPException(response, data)
nextcord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embeds.0.fields.4.value: This field is required

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

Traceback (most recent call last):
  File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\bot.py", line 1055, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 933, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 177, in wrapped
    raise CommandInvokeError(exc) from exc
nextcord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
frozen patio
#
In embeds.0.fields.4.value: This field is required
sick birch
#

Embed 0 field 4 seems to be where the issue is

nova bear
#

thats where im getting confused

sick birch
#

Can you send the code where you construct the embed?

spring flax
sick birch
#

When it sees that message, it'll get the message and store it within m

frozen patio
sick birch
#

Then you can do regular stuff on it like m.contents

nova bear
#

so m is message basically

sick birch
#

Same as you might for, say, on_message(message)

frozen patio
#
@client.command()
async def userinfo(ctx, user: nextcord.Member=None):
    if ctx.author.id in blacklist: 
        bl = nextcord.Embed(title="You are blacklisted!", description="You have been blacklisted from Slytherin!", color=0xff0000)
        bl.set_footer(text=footer)
        bl.timestamp = datetime.now()
        await ctx.send(embed=bl)
    else:
        if user is None:
            user = ctx.author
        if user.id in staff:
            staff_status = True
        else:
            staff_status = False
    
        role_count = len(ctx.guild.roles)
        roles_count = len(user.roles)

        role_list = [r.mention for r in user.roles if r != ctx.guild.default_role]
        roles = ", ".join(role_list)

        perm_list = [perm[0] for perm in user.guild_permissions if perm[1]]


        embed = nextcord.Embed(title=f"User Info for {user.name}", color=0x003fff)
        embed.add_field(name="User ID", value=user.id, inline=False)
        embed.add_field(name="Creation Date", value={user.created_at}, inline=False)
        embed.add_field(name="Joined Server", value=user.joined_at, inline=False)
        embed.add_field(name="Server Manager Staff", value=staff_status, inline=False)
        embed.add_field(name="Roles List", value=roles, inline=False)
        embed.add_field(name="Roles Count", value=roles_count, inline=False)
        embed.add_field(name="Permissions", value=perm_list, inline=False)
        embed.set_footer(text=footer)
        embed.timestamp = datetime.now()
        embed.set_thumbnail(url=user.avatar.url)
        await ctx.reply(embed=embed)
sick birch
nova bear
#

ok so where can i store that in the command

blissful sparrow
slate swan
#
@bot.event
async def on_member_join(member):
  verifychannel = bot.get_channel(963258610815733830)
  await verifychannel.send(f"{member}, verify to gain access to the server!")```
why does my join message does not do anytbing?
slate swan
spring flax
#

!intents

unkempt canyonBOT
#

Using intents in discord.py

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

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

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

from discord import Intents
from discord.ext import commands

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

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

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

sick birch
spring flax
sick birch
#

Either that or embed.add_field(name="Roles List", value=roles, inline=False)

#

Depending on if discord 0 indexes their fields

sick birch
#

I'm guessing roles is an empty list, and by extension and empty string

spring flax
#

You're passing None in one field value

frozen patio
sick birch
#

Looks like it's an intents problem where it's not giving you the proper roles maybe?

frozen patio
#

so it's not empty

sick birch
frozen patio
#

Maybe if I make a role

frozen patio
sick birch
#

and the person you're running the command on has the bot role?

nova bear
#

im still a bit confused when it comes to the whole role and deleting message thing lol

sick birch
#

Take it step by step and set up a proper wait_for first

blissful sparrow
# spring flax Code?
@commands.command()
    @commands.is_owner()
    async def leave(self,ctx, guild: discord.Guild=None):
        if guild is None:
            id = ctx.guild.id 
            guild = self.bot.get_guild(id)
            await guild.leave()
            print(f"Successfully left guild: {guild.name}")
        else:
            id = guild.guild.id()
            guild = self.bot.get_guild(id)
            await guild.leave()
            print(f"Successfully left guild: {guild.name}")

Indentation a bit off here cos vsc

spring flax
nova bear
spring flax
#

Remove py id = guild.guild.id()
@blissful sparrow

sick birch
# nova bear

Yeah that's good. I suggest you read the documentation for wait_for though

#

!d discord.Client.wait_for

unkempt canyonBOT
#

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

Waits for a WebSocket event to be dispatched.

This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way.

The `timeout` parameter is passed onto [`asyncio.wait_for()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for "(in Python v3.10)"). By default, it does not timeout. Note that this does propagate the [`asyncio.TimeoutError`](https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.TimeoutError "(in Python v3.10)") for you in case of timeout and is provided for ease of use.

In case the event returns multiple arguments, a [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.10)") containing those arguments is returned instead. Please check the [documentation](https://discordpy.readthedocs.io/en/master/api.html#discord-api-events) for a list of events and their parameters.

This function returns the **first event that meets the requirements**...
nova bear
#

what next? il check that out in a lil

sick birch
#

You need to get a proper wait for going first

#

Do you have that? With a proper check and a timeout along with error handling

spring flax
blissful sparrow
spring flax
#

@blissful sparrow in the guild.leave in the else statement put leave(guild.id)

blissful sparrow
spring flax
#

You don't need to get the guild

final iron
#

!d discord.ext.commands.Context returns a guild object with the guild attribute

unkempt canyonBOT
#
class discord.ext.commands.Context(*, message, bot, view, args=..., kwargs=..., prefix=None, command=None, invoked_with=None, invoked_parents=..., invoked_subcommand=None, ...)```
Represents the context in which a command is being invoked under.

This class contains a lot of meta data to help you understand more about the invocation context. This class is not created manually and is instead passed around to commands as the first parameter.

This class implements the [`Messageable`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.Messageable "discord.abc.Messageable") ABC.
nova bear
#

i have messages in the wait

sick birch
#

You also need a check and a timeout

blissful sparrow
sick birch
#

By default wait_for picks up the FIRST message it sees, regardless of where or whom it's from

#

which is undeseriable

nova bear
#

ohh

#

so then i would need the check

blissful sparrow
#

oh wait u mean in the else statement?

nova bear
#

so could i do this

muted dagger
#

@slate swan i need your help please, sorry if im makin you spoonfeed or annoyed, but can you show me how to make a ban command

spring flax
#

@blissful sparrow remove the get_guild in the else statement

blissful sparrow
spring flax
#

And change it to in the first part ```py
if guild is None:
await ctx.guild.leave()

#

Code

blissful sparrow
slate swan
#

How can I let my bot check if the authors id is in the text file and if not send a message like youre not in the list buddy and if hes in the list it just goes with it and does what it should do?

I use aiofiles

spring flax
blissful sparrow
#

say what now?

spring flax
#

Not await guild.leave(guild.id)

blissful sparrow
#
@commands.command()
@commands.is_owner()
async def leave(self,ctx, guild: discord.Guild=None):
        if guild is None:
            id = ctx.guild.id 
            guild = self.bot.get_guild(id)
            await ctx.guild.leave()
            print(f"Successfully left guild: {guild.name}")
        else:
            await guild.leave(guild.id)
            print(f"Successfully left guild: {guild.name}")

#

where exactly?

muted dagger
#

im a lonely hikari user

spring flax
#

Wrong

blissful sparrow
#

Oh that workd

#

Thanks!!!!!!!

slate swan
#

i mean, did you write anything yet?

nova bear
muted dagger
#

then it popped into my mind

slate swan
# muted dagger then it popped into my mind

oh well you would have to use a member option with hikari.Member type py @lightbulb.option("member", "member to ban", type=hikari.Member) you can access it with ctx.options.member & ban the member using await ctx.options.member.ban()

blissful sparrow
#

I tried to derive my ban command from my kick command but it didnt go to plan

muted dagger
#

just wait

#
@bot.command
@lightbulb.add_checks(lightbulb.owner_only)
@lightbulb.option("member", "member to ban", type=hikari.Member)
@lightbulb.command("ban", Ban a user")
@lightbulb.implements(lightbulb.SlashCommand)
async def ban(ctx: lightbulb.Context) -> None:
    await ctx.respond(ctx.options.member.ban()```
slate swan
#

nah, you dont create a response with it

muted dagger
#

ohh

slate swan
#

first, you need to ban that user py async def ban(context): await context.options.member.ban() # then create a response if you want to await context.respond(...)

#

and you didnt open the " in the command decorator

slate swan
#

yeah

muted dagger
#

ik

#

alright

#

thanks man!

slate swan
#

if you dont like using context.options again and again, you may use the pass_options arg to the command decorator, makes life easier

muted dagger
#
@bot.command
@lightbulb.add_checks(lightbulb.owner_only)
@lightbulb.option("member", "Member to ban", type=hikari.Member)
@lightbulb.command("ban",  "Ban a user")
@lightbulb.implements(lightbulb.SlashCommand)
async def ban(context):
    await context.options.member.ban()
    await context.respond(Banned User Successfully)```
#

afk brb

slate swan
#
@option("my_arg", "description")
@command("command", "desc", pass_options=True)
@implements(...)
async def command(context, my_arg):
``` is another way to access the arg
slate swan
muted dagger
#

thanks so much man, im indebted to you

slate swan
#

pleasure

lucid bison
#

how would i add buttons using reactions to an embed?

supple thorn
lucid bison
#

could i see an example of the waiting for?

supple thorn
#

!d discord.ext.commands.Bot.wait_for

unkempt canyonBOT
#

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

Waits for a WebSocket event to be dispatched.

This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way.

The `timeout` parameter is passed onto [`asyncio.wait_for()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for "(in Python v3.10)"). By default, it does not timeout. Note that this does propagate the [`asyncio.TimeoutError`](https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.TimeoutError "(in Python v3.10)") for you in case of timeout and is provided for ease of use.

In case the event returns multiple arguments, a [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.10)") containing those arguments is returned instead. Please check the [documentation](https://discordpy.readthedocs.io/en/master/api.html#discord-api-events) for a list of events and their parameters.

This function returns the **first event that meets the requirements**...
lucid bison
#

so.... await wait_for(event)?

supple thorn
#

That sucked absolute ass typing with only one hand

lucid bison
#

ok so who will be the author when the bot is doing a command?

#

and what about multiple reactions

supple thorn
#

The person who invoked the command

lucid bison
#

ok and how do i check for multiple reactions line true or false

supple thorn
#

And just switch them inside of a if statement

lucid bison
#

what will it return when using it with reactions?

supple thorn
#

The reaction

lucid bison
#

like the emoji?

slate swan
#

its always reaction& user., or payload if you use the raw event

supple thorn
#

I forgot about user

lucid bison
#

TypeError: GatewayBot.wait_for() got an unexpected keyword argument 'check'

slate swan
#

please mention the library you use from the next time

#

you're using hikari right?

lucid bison
#

ye

supple thorn
#

Bruh

supple thorn
#

I can't help you

#

I got no clue how to help with hikari

#

Maybe ask sarth i saw him helping with hikari

slate swan
supple thorn
#

Good luck sarth

lucid bison
#

what unit the the timeout in?

slate swan
#
reaction_event = await bot.wait_for(hikari.ReactionAddEvent, predicate=your_check, timeout= float/int)```
lucid bison
#

i meant like seconds/minutes

slate swan
#

Seconds , and it's 180 by default

lucid bison
#

ok

green bluff
#

i dont get it request is clearly None yet it doesnt print rundr2

slate swan
#

why the () around the placeholders

#

remove them, and make sure you get the correct data type there

#

you can use the sqlite viewer extension to check that

green bluff
#

like the db browser?

vale wing
#

DB Visualiser for all databases is good ๐Ÿ‘

slate swan
#

nah vsc has an extension for viewing sqlite files im talking about that

vale wing
#

But VCS has some extensions for viewing databases inside

#

Not very convenient imho cuz you can't execute scripts

green bluff
vale wing
#

Maybe you can but I didn't find it

slate swan
#

true, thats a read-only

green bluff
#

so uh the datatype for computer is text

slate swan
# green bluff

expand the user_id column so you can see if the complete user id is entered

#

i doubt if the full id was inserted since INT doesnt allow that

green bluff
#

it matches cause

slate swan
#

can i see your "CREATE TABLE" statement?

vale wing
#

Did you remove those brackets in your queries

green bluff
#

but the request is none

slate swan
#

mhm then those brackets may be the issue, remove them

green bluff
#

so why isnt it executing the if statemtn

#

even without the brackets wont the result be the same?

slate swan
#

no wait

#

Computer is None

green bluff
#

ik and i made an if statement

slate swan
#

so the request variable is ((None))

green bluff
#

if None rone this but it didnt

slate swan
#

which is None

green bluff
#

run

#

it didnt run the statement which was none

slate swan
#

because request is (None,)

green bluff
#

yea and python can read through tuples

slate swan
#

!e py print(None == (None,)) is false

unkempt canyonBOT
#

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

False
green bluff
#

waht?

#

how did it work for my other commands then

#

ok ill just be safe and do that

slate swan
#

because that was just None

green bluff
cosmic agate
#

how to add?

#
for fn in os.listdir("./cogs"):
    if fn.endswith(".py"):
        bot.load_extension(f"cogs.{fn[:-3]}")
```AttributeError: module 'cogs.venture' has no attribute 'setup'
tiny ibex
muted dagger
lucid bison
#

msg = await bot.wait_for(hikari.ReactionAddEvent, timeout=180) how do i check who added the reaction

slate swan
slate swan
#

Get the user from cache using bot.cache.get_user(id)

lucid bison
#

for hikari right

slate swan
#

Yessir

lucid bison
#

AttributeError: 'GuildReactionAddEvent' object has no attribute 'author_id'

slate swan
#

Try user_id

muted dagger
slate swan
#
  File "/home/runner/tester/cogs/rostermenu.py", line 86, in rostermenu
    await ctx.respond(embed=embed)
AttributeError: 'Context' object has no attribute 'respond'

``` any idea?
muted dagger
slate swan
#

its their

#

await ctx.respond(embed=embed)

muted dagger
#

and what are you trying to make? if its an embed i can give you an example

slate swan
#

i know how to make an embed its saying context has no attriubite to respond

#

e.g await ctx.respond(embed=embed)

muted dagger
#

async def ping(ctx: lightbulb.Context) -> None:

#

did you have something like that?

slate swan
#

no

muted dagger
#

above the await?

slate swan
#

just async def ping(ctx)

muted dagger
slate swan
#

async def rostermenu(self, ctx):

muted dagger
#

try that

slate swan
muted dagger
#

wait

#

what libraries are you using?

slate swan
#

pycord

muted dagger
#

ohhh

slate swan
#

beta branch

muted dagger
#

well, pycord is heavily outdated

slate swan
muted dagger
#

use hikari and tanjun/lightbulb

#
pip install hikari-lightbulb```
slate swan
#

i dont really likts is functions/classes

#

the naming of it yk

slate swan
muted dagger
slate swan
#

context.respond is indeed in pycord

#

ive used it in plenty of times

slate swan
slate swan
#

ah

muted dagger
#

soooo

#

use hikari, thats all we can say

slate swan
muted dagger
slate swan
#

guess so.

#

i could just use visual to just replace everything

muted dagger
muted dagger
slate swan
#

Yep

muted dagger
#

alright, then you do know the meme command right?

#

well i tried to replicate it in lightbulb but its giving me errors

#

tried to do a little plugins thing

slate swan
#

show code

muted dagger
#
import hikari
import lightbulb

fun_plugin = lightbulb.Plugin("Fun")


@fun_plugin.command
@lightbulb.command("fun", "All the entertainment commands you'll ever need")
@lightbulb.implements(lightbulb.SlashCommandGroup, lightbulb.PrefixCommandGroup)
async def fun_group(ctx: lightbulb.Context) -> None:
    pass  # as slash commands cannot have their top-level command ran, we simply pass here


@fun_group.child
@lightbulb.command("meme", "Get a meme")
@lightbulb.implements(lightbulb.SlashSubCommand, lightbulb.PrefixSubCommand)
async def meme_subcommand(ctx: lightbulb.Context) -> None:
    async with ctx.bot.d.aio_session.get(
        "https://meme-api.herokuapp.com/gimme"
    ) as response:
        res = await response.json()

        if response.ok and res["nsfw"] != True:
            link = res["postLink"]
            title = res["title"]
            img_url = res["url"]

            embed = hikari.Embed(colour=0x3B9DFF)
            embed.set_author(name=title, url=link)
            embed.set_image(img_url)

            await ctx.respond(embed)

        else:
            await ctx.respond(
                "Could not fetch a meme :c", flags=hikari.MessageFlag.EPHEMERAL
            )


def load(bot: lightbulb.BotApp) -> None:
    bot.add_plugin(fun_plugin)```
slate swan
#

The error?

muted dagger
slate swan
#

use only extensions

#

Without the ./

muted dagger
#

k

slate swan
#

The / at end too

#

Why does my bot only read the newest line with aiofiles?
In the second screenshot you can see i am on the list but my bot doesnt read all lines

muted dagger
slate swan
#

Did it work?

muted dagger
slate swan
#

How do you run your code? The play button?

muted dagger
slate swan
#

its a seperate branch but it could work!

muted dagger
slate swan
#

use the run option on the top of vscode

muted dagger
slate swan
muted dagger
#

dont

slate swan
#

is disnake worse than pycord?

#

tbh , I hate discord.py's app command Implementation

muted dagger
slate swan
#

If I were to sort it accordingly to my preference it would be

#

Causing for everyone to switch libs then he wants to come back and then not be friendly to forks. even if their fork is lisenced under MIT

#

discord.py app commands are too weird like what in the world is a CommandTree

muted dagger
#

but im happy with my results anyway

slate swan
#

Ill check it out once more.

#

What was the thing actually?

muted dagger
slate swan
#

it would be same as discord.py or any other library except for how you send it

muted dagger
#

๐Ÿง  = 0.1

dull terrace
#

finally got my little blackjack minigame working with its visuals pepe_cheer

#

can only fit 5 cards on screen but thatll have to do

slate swan
slate swan
slate swan
#

Pycord spiked me with their new beta release, where commands automatically can get translated to both slash and regular command

#

and their auto components pagination. I wish discord had a offical libaries.

cosmic agate
#
Ignoring exception in on_ready
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nextcord/client.py", line 415, in _run_event
    await coro(*args, **kwargs)
  File "/Volumes/FLASH DRIVE/Palisade2.0/main.py", line 103, in on_ready
    setattr(bot, "db", await aiosqlite.connect("levels.db"))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiosqlite/core.py", line 137, in _connect
    self._connection = await future
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiosqlite/core.py", line 102, in run
    result = function()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiosqlite/core.py", line 397, in connector
    return sqlite3.connect(loc, **kwargs)
sqlite3.OperationalError: unable to open database file
slate swan
#

What would you guys say about NextCord?

muted dagger
cosmic agate
#

its food

#

i mean good

#

i use it as my daily driver

slate swan
#

it's a fork

#

You use it to have ur food

slate swan
slate swan
#

is it more updated?

muted dagger
slate swan
#

nextcord? No

cosmic agate
#

no

slate swan
#

so its below pycord?

muted dagger
cosmic agate
muted dagger
#

Hikari--
Discord.py (M)--
Pycord--
Disnake--
NextCord--

cosmic agate
slate swan
#

I think im going to select disnake.

cosmic agate
slate swan
#

I believe pycord has the best features.

#

like?

#

it may not be updated but pycord has the best features imo

cosmic agate
#

๐Ÿ‘๐Ÿผ

slate swan
#

the ones ive listed before **addition features not like slash_commands dropdowns **

cosmic agate
#

nextcord also have those

slate swan
#

i said not like

#

like autopagination, and like automatic converting

#

!pip discord-ext-menus

unkempt canyonBOT
slate swan
#

The auto pagination

#

could u show me a callback example

#

in hikari

cosmic agate
#

not my forte unfortunately

slate swan
muted dagger
#

my brain isnt smart enough for hikari

muted dagger
# slate swan A command callback?

Sarth, and dont worry this is the last time i'll annoy you, but could you show me a example or create an example of a meme command

blissful sparrow
#

Whats a way to see if @commands.check_any() has been satisfied?

slate swan
#

How do I react to a message with the message ID?

#

!d discord.TextChannel.fetch_message

unkempt canyonBOT
#

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

Retrieves a single [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") from the destination.
slate swan
#

And use .add_reactions on it

lucid bison
#

im using @bot.command @lb.command('quiz', 'quiz') @lb.implements(lb.PrefixCommand) async def quiz(ctx): how could i get the id of the channel from ctx?

slate swan
#

how to get guild id?

slate swan
slate swan
lucid bison
#

thx

#

ctx.channel_id worked

echo wasp
#

what are the reqirements needed to run a basic bot?

lucid bison
#

wdym?

slate swan
#

why does it not detect anyone but the first guy?

echo wasp
slate swan
echo wasp
lucid bison
#

?

echo wasp
astral adder
#

Pro Coders Here thinkmon

echo wasp
twilit thistle
#

hello guys

#

I have a question

slate swan
#

Do u mean
content = ["id", "id"]?

My list is a .txt file with a member name every new line @echo wasp

astral adder
twilit thistle
#

what kind of modules do I need to make a bot

#

also...

astral adder
twilit thistle
#

do I need a Database?

lucid bison
#

nope

astral adder
twilit thistle
#

thx

#

for your help

astral adder
#

Np

echo wasp
slate swan
echo wasp
# echo wasp Yep but " " is not needee it an int

try this i use to have a user .txt file py with open('User list.txt','r') as file: ids = tuple((int(x.strip()) for x in file.readlines() if x.strip().isdecimal())) if ctx.message.author.id in ids:

echo wasp
muted dagger
slate swan
echo wasp
echo wasp
muted dagger
#

nextcord...

slate swan
#

how do i reply to a message in discord.py with just it's id?

echo wasp
#

Heroku requirements.txt needed to run a discord bot what all them

echo wasp
slate swan
echo wasp
#

what are you trying todo

#

@slate swan

#

!d discord.Message.reply

unkempt canyonBOT
#

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

A shortcut method to [`abc.Messageable.send()`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.Messageable.send "discord.abc.Messageable.send") to reply to the [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message").

New in version 1.6.

Changed in version 2.0: This function will now raise [`TypeError`](https://docs.python.org/3/library/exceptions.html#TypeError "(in Python v3.10)") or [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.10)") instead of `InvalidArgument`.
slate swan
#

I already figured it out.

#

using requests how can I change the color of the embed wehook?

echo wasp
slate swan
#

I didn't mean to type json

echo wasp
slate swan
#

discord api

#

@slate swan

#

Don't wanna use it

echo wasp
#

if it am correct

slate swan
slate swan
echo wasp
#

you specify the embed before you send it so something like this

slate swan
slate swan
slate swan
slate swan
#

Why can't you use discord api?

slate swan
slate swan
echo wasp
#
embed=discord.Embed(title="hello", description="whatever")
webhook = Webhook.from_url('url-here', adapter=AsyncWebhookAdapter(session))
        await webhook.send(username='Foo', embed=embed)``` something like that?
slate swan
#

No

#

that's with discord's api

echo wasp
#

then i'm confused

slate swan
slate swan
slate swan
# slate swan why not

Because it's annoying, and you're going out of your way to make it different and the end product is the same.

echo wasp
#

walks away

slate swan
#

Ok.

#

I've sent that before. Lol.

slate swan
#

not the same thing

#

Yes it is.

#

sure

echo wasp
#

comes back with ๐Ÿฟ and sits and watches

paper sluice
#

this is the only topical channel will cooldown ๐Ÿ˜”

slate swan
#

@slate swan If you wanna see the code I figured it out ๐Ÿ˜„

#

@echo wasp I just realized that the command to see all user in that list is now only showing the ids, do you know how i could make it to mentions/names again? sorry for the ping

slate swan
slate swan
#

Or if you want name, get the user using bot.get_user(id) and use the name property

slate swan
#

all the ids are in a txt file

#

Iterate thru content.split("\n")
That would be a list of ids

#

and then do a list comprehension which mentions the user's

serene lynx
#

what is the class name for custom raise error slashcommand in nextcord?

slate swan
#

yup

echo wasp
formal basin
#

I donโ€™t understand this error

placid skiff
formal basin
#

But this one no

pine shuttle
#

hi, I m new to discord.py , I don't know why this error coming. Help me to figure out friends.

placid skiff
#

that is a python exception btw you are trying to import two or more times, by a circular import, the same package

slate swan
#

why does this not work? there is no error

slate swan
slate swan
slate swan
#

..

slate swan
serene lynx
muted dagger
#

can you people tell me how this works
adding images onto images AT A CERTAIN POSITION

boreal ravine
#

you get the image

#

you place another image onto the other image at a certain coordinate

muted dagger
# slate swan why not

At this very moment, with unswerving and immaculate penetration, you are on the verge between being an absolute shithead and a dumbo.
Honetly, use a API Wrapper and a Command Handler correctly, ffs

muted dagger
#

and how do i do that

muted dagger
#

thats the point

boreal ravine
blissful sparrow
#

This may be a stupid question but is it possible for example to make a help command with drop menus an ephemeral?

boreal ravine
#

yes

blissful sparrow
tacit token
#

Hi friends, how can i get the channel with webhooks?

a=webhook.channel(825463704384438283)
webhook.send(f"{a}")
slate swan
tacit token
#

from discord import SyncWebhook

muted dagger
tacit token
#

yeah

#

im a developer one a big server and the server need webhooks

muted dagger
tacit token
#

unfortunately i don't understand webhooks

slate swan
muted dagger
tacit token
#

i try mention other channel in 1 server

muted dagger
slate swan
#

sorry I do not understand.

muted dagger
slate swan
#

if english is not your first language perhaps use a translator

tacit token
#

So i have 2 channel, i try mention channel 2 with channel 1 intention (in dpy -> (channel.mention) but i need this in webhook)

muted dagger
#

???

slate swan
slate swan
#

why is my bot not sending the embed? everything else works fine but it just wont send the embed

tacit token
#
from discord import SyncWebhook
import discord
webhook = SyncWebhook.from_url("url")
a=webhook.channel(825463704384438283)
webhook.send(f"{a}")
muted dagger
#

@slate swan

slate swan
#

idk if u meant that

muted dagger
slate swan
#

yes

slate swan
muted dagger
tacit token
#

so this is the mention, my bot use it

muted dagger
#

Pycharm, Visual Studio.

slate swan
#

@tacit token you could use requests instead of discord.py

slate swan
muted dagger
slate swan
slate swan
muted dagger
vale wing
#

Requests bad for async

slate swan
#

works for me

vale wing
#

If the server takes long to respond it will block your whole bot

slate swan
muted dagger
vale wing
#

Anyways if you are using requests in async app that's bad practice

slate swan
muted dagger
#

thats why

cosmic agate
#

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nextcord/ext/commands/core.py", line 168, in wrapped
ret = await coro(args, **kwargs)
File "/Volumes/FLASH DRIVE/Palisade2.0/main.py", line 599, in afk
await cursor.execute("INSERT INTO afk (user, guild reason) VALUE (?, ?, ?)", (ctx.author.id, ctx.guild.id, reason,))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiosqlite/cursor.py", line 37, in execute
await self._execute(self._cursor.execute, sql, parameters)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiosqlite/cursor.py", line 31, in _execute
return await self._conn._execute(fn,args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiosqlite/core.py", line 129, in _execute
return await future
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiosqlite/core.py", line 102, in run
result = function()
sqlite3.OperationalError: near "reason": syntax error

vale wing
#

SQL query wrong

slate swan
vale wing
#

Print the query you are submitting

cosmic agate
#
@bot.command()
async def afk(ctx, *, reason = None):
    if reason == None:
        reason = "No reason provided"
    async with bot.db.cursor() as cursor:
        await cursor.execute("SELECT reason FROM afk WHERE user = ? AND guild = ?", (ctx.author.id, ctx.guild.id,))
        data = await cursor.fetchone()
        if data:
            if data[0] == reason:
                return await ctx.send("You are already afk with the same reason!")
            await cursor.execute("UPDATE afk reason = ? WHERE user = ? AND guild = ?", (reason, ctx.author.id, ctx.guild.id,))
        else: 
            await cursor.execute("INSERT INTO afk (user, guild reason) VALUE (?, ?, ?)", (ctx.author.id, ctx.guild.id, reason,))
            await ctx.send(f"You are now afk for {reason}")
        await bot.db.commit()
cosmic agate
#

??

muted dagger
vale wing
#
UPDATE afk SET reason = ? ...```
#

You don't have SET

cosmic agate
#

hmm

vale wing
#

And yeah VALUES not VALUE

slate swan
vale wing
#

Is title even a necessary kwarg

#

Ima go check

#

Yeah it's optional

placid skiff
slate swan
plain perch
#

One message removed from a suspended account.

#

One message removed from a suspended account.

umbral night
#
@bot.command()
async def servericon(ctx):
  embed = discord.Embed(title = f"{ctx.guild.name}'s icon", color=0x36393F)
  embed.set_image(url=ctx.guild.icon)
  await ctx.send(embed = embed)

why doesnt this work?

placid skiff
#

doesn't send the embed?

umbral night
#

it doesnt send anything

#

and there arent any errors in the ide

placid skiff
#

Ok thought that discord had some problem with embed but mine works fine xD

plain perch
umbral night
#

i need help

placid skiff
quick garnet
#

Can anyone help me for a code in python? So I have a jail cmd and if I get him out he has no roles roles I can write that in code that he gets his roles back when he is released

slate swan
#

Does my bot need an extra intent for creating and deleting webhooks?

placid skiff
placid skiff
placid skiff
quick garnet
placid skiff
#

json is not a storage method, json represents javascript object as text

quick garnet
#

But how do I do that in code can't you help me I'm new to the scene

quick garnet
placid skiff
#

!d discord.Member.add_roles
this is used to add roles to a member

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.
umbral night
#

how do i define the guild name

#

or _name

placid skiff
umbral night
#

or what

#

@placid skiff do u know

placid skiff
unkempt canyonBOT
placid skiff
#

you can't define it, every guild has it's own name

modest harbor
#

can i use on_message and edit the message without using ctx?

unkempt canyonBOT
#

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

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

Warning

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

yea but like can i edit the message afterwards with it

#

can i use f string in it?

#

alright thanks lemme try

#

yea im aware of that

boreal ravine
#

anyone have any bot ideas?

desert cosmos
#

!d discord.Message.mentions

unkempt canyonBOT
#

A list of Member that were mentioned. If the message is in a private message then the list will be of User instead. For messages that are not of type MessageType.default, this array can be used to aid in system messages. For more information, see system_content.

Warning

The order of the mentions list is not in any particular order so you should not rely on it. This is a Discord limitation, not one with the library.

slate swan
desert cosmos
flat solstice
#

what am I doing wrong with these events? They don't seem to be sending when I mute/defa/self_mute my alt, I don't think I really need to be checking if before != after but I'm doing it more out of habit```py
if before.mute != after.mute: # Member muted/unmuted
embed.title = "Muted",
embed.description = f"{'Unmuted' if after.muted else 'Muted'}",
if before.deaf != after.deaf: # Member deafened/undeafened
embed.title = "Deaf",
embed.description = f"{'Undeaf' if after.deaf else 'Deaf'}",
if before.self_mute != after.self_mute: # Member self-muted/unmuted
embed.title = "Self Muted",
embed.description = f"{'Unmuted' if after.self_mute else 'Muted'}",
if before.self_deaf != after.self_deaf: # Member self-deafened/undeafened
embed.title = "Self Deaf",
embed.description = f"{'Undeaf' if after.self_deaf else 'Deaf'}",
if before.self_stream is not after.self_stream:
embed.title = "Self Stream",
embed.description = f"{'Unstreamed' if after.self_stream else 'Streamed'}",

if before.self_video is not after.self_video:
embed.title = "Self Video",
embed.description = f"{'Unvideoed' if after.self_video else 'Videoed'}",
if before.suppress is not after.suppress:
embed.title = "Suppressed",
embed.description = f"{'Unsuppressed' if after.suppress else 'Suppressed'}",
if before.requested_to_speak_at is not after.requested_to_speak_at:
embed.title = "Requested to speak at",
embed.description = f"<t:{int(after.requested_to_speak_at)}:R> ",```

flat solstice
spring flax
#

what's the event you're using?

flat solstice
surreal ruin
#

Like this

#

Please can anyone help ke

surreal ruin
slate swan
#

This is for discord bots.

surreal ruin
#

Oh

slate swan
flat solstice
spice bramble
#

guys I just made a discord bot

slate swan
#

nice

spice bramble
#

it gives info on programming langs and gives their website link

surreal ruin
#

@slate swan i making a pokemon discord bot

plucky sundial
spice bramble
#

guys do you wanna join my server?

#

i need more programmers in it

#

if youre a pro, pls join it

maiden fable
#

Not the correct server for the same

slate swan
#

hunter youre a pro

#
@commands.Cog.listener()
    async def on_raw_reaction_remove(self, payload):
        
        messageID=962844879044628510

        if messageID== payload.message_id:
            guild= self.bot.get_guild(payload.guild_id)
            member = guild.get_member(payload.user_id)
        
        if str(payload.emoji) == ":black_drip:":
            role = get(guild.roles, name='evnt')
        elif str(payload.emoji) == ":Uzi_spin:":
            role = get(guild.roles, name='chat revive')
        elif str(payload.emoji) == ":BlackFire:":
            role = get(guild.roles, name='gw')
        elif str(payload.emoji) == ":Black_LV:":
            role = get(guild.roles, name=':Black_LV:')
        else:
            role = discord.utils.get(guild.roles, name=payload.emoji)
            
        if role is not None:
            await member.remove_roles(role)
        print(f"Removed {role} from {member}.")
        print(str(payload.emoji))
#

so i have this code here

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.

slate swan
#

and basically when i try to remove it

#

why use reactions? and not buttons?

#

idk

#

i lke reactions

boreal ravine
slate swan
#

i like reactions

#

more than buttons

#

you probably like having a bigger ratelimit as well?

#

isnt reactions like 1/1s

#

well idk

boreal ravine
flat solstice
#

tl:dr Should I keep my log colours consistent across different type of logs?

Okay so I have a aesthetic question. I'm currently using discord.Colour.teal() for members joining a vc/stage, discord.Colour.dark_magenta() for members leaving a vc/stage and discord.Colour.dark_teal() for members moving between vcs/stages. I'm not too sold on the dark_teal and teal posistions so might swap them around.

This brings me onto my question: What colour(s) should I make guild mute, self mute, guild def, self deaf, self stream, self video, supressed and requested to speak? I'm thinking that the mutes should be a red but two different shades and the deafs should be greys not I'm not too sure on the stream, video etc. I'm also not sure if I should keep all of 'true' type logs in a green/teal colour, all of the 'false' logs in a red/magenta colour and 'misc' in a blue/orange colour (talking about all logs here not just vc/stage logs) as I'm currently using

  • diiscord.Colour.green() and diiscord.Colour.red() for bot joining/leaving guilds respectively,
  • diiscord.Colour.green(), diiscord.Colour.red(), diiscord.Colour.orange() and diiscord.Colour.yellow() for my bots shard ready/disconnects/connects/resumes respectively
  • diiscord.Colour.red(), diiscord.Colour.dark_orange() and diiscord.Colour.dark_red() for message deletes/edits/bulk deletes respectively

So as you can see it's not really that consistent across my logs and I'm not sure if it should be. On one hand I think it's important to have consistencies across the logs and on the other hand I'm thinking these events are similar enough to have some crossed colours but they are also different enough not not need crossed colours.

slate swan
#

it basically prints removed None instead of actually removing a role

slate swan
cosmic agate
#

Ignoring exception in command afk:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nextcord/ext/commands/core.py", line 168, in wrapped
ret = await coro(args, **kwargs)
File "/Volumes/FLASH DRIVE/Palisade2.0/main.py", line 597, in afk
await cursor.execute("UPDATE afk reason = ? WHERE user = ? AND guild = ?", (reason, ctx.author.id, ctx.guild.id,))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiosqlite/cursor.py", line 37, in execute
await self._execute(self._cursor.execute, sql, parameters)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiosqlite/cursor.py", line 31, in _execute
return await self._conn._execute(fn,args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiosqlite/core.py", line 129, in _execute
return await future
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiosqlite/core.py", line 102, in run
result = function()
sqlite3.OperationalError: near "reason": syntax error
this da error

@bot.command()
async def afk(ctx, *, reason = None):
    if reason == None:
        reason = "No reason provided"
    async with bot.db.cursor() as cursor:
        await cursor.execute("SELECT reason FROM afk WHERE user = ? AND guild = ?", (ctx.author.id, ctx.guild.id,))
        data = await cursor.fetchone()
        if data:
            if data[0] == reason:
                return await ctx.send("You are already afk with the same reason!")
            await cursor.execute("UPDATE afk reason = ? WHERE user = ? AND guild = ?", (reason, ctx.author.id, ctx.guild.id,))
        else: 
            await cursor.execute("INSERT INTO afk (user, guild, reason) VALUES (?, ?, ?)", (ctx.author.id, ctx.guild.id, reason,))
            await ctx.send(f"You are now afk for {reason}")
        await bot.db.commit()
#

this da code

quick gust
#

not sure but i dont think that's how u make an UPDATE query

visual island
bleak karma
#

can someone tell me whats wrong with this

  @commands.command()
  async def ban(self, ctx, member: int, *, reason=None):
    user = await self.bot.get_user(int(member))
    if user in ctx.guild:
      e = discord.Embed()
      e.description = f"banned {user.mention}"
      e.colour = 0x2f3235
      await ctx.send(embed=e)

      m = discord.Embed()
      m.description = "you have been banned."
      m.colour = 0x2f3235
      await user.send(embed=m)
      await ctx.guild.ban(user)
    else:
      e = discord.Embed()
      e.description = f"banned"
      e.colour = 0x2f3235
      await ctx.send(embed=e)
      await ctx.guild.ban(member)

it wont give an error :(( + it wont ban & send the embed

cosmic agate
bleak karma
cosmic agate
#

u need title for embed to work

#

ig

bleak karma
cosmic agate
#

hmm

bleak karma
#

w/o a title

cosmic agate
#

?

#

wdym

bleak karma
cosmic agate
#

like any output

bleak karma
cosmic agate
#

hmm

supple thorn
final iron
cosmic agate
#

i see

bleak karma
#

does ctx.guild.members work?

final iron
#

Yeah

bleak karma
#

it works tysm

final iron
#

Just typehint member to discord.Member so you don't have to get the member

flat solstice
#

is there a way I can iterate over all of the colours in discord.Colour? I tried for colour in discord.Colour and gotpy Ignoring exception in on_ready Traceback (most recent call last): File "C:\Users\Teagan\Documents\Coding\Zupie\env\lib\site-packages\discord\client.py", line 375, in _run_event await coro(*args, **kwargs) File "C:\Users\Teagan\Documents\Coding\Zupie\bot\cogs\events.py", line 60, in on_ready for colour in Colour: TypeError: 'type' object is not iterable

cosmic agate
#

show code

supple thorn
#

Snowy already said what they did already

flat solstice
# cosmic agate show code

I have, I'm literally just doing```py
from discord import Colour

for colour in Colour:```and I'm running this inside my ready event (as a test use case since testing it here was a quick way to check if the code is valid if not why not)

bleak karma
cosmic agate
#

why u want to import colour?

cosmic agate
bleak karma
#

discriminator?

supple thorn
#

Transil asking the wrong questions

cosmic agate
#

?

cosmic agate
bleak karma
supple thorn
supple thorn
flat solstice
# cosmic agate why u want to import colour?

for use in embeds, it's just saving my namespace so I don't just dopy import discordI can just import the things I actually need in my namespace likepy from discord import Colour, Embed, app_commands

supple thorn
bleak karma
cosmic agate
bleak karma
#

from discord import commands ?

supple thorn
cosmic agate
#

or import discord

flat solstice
#

@supple thorn do you have any advice?

supple thorn
supple thorn
#

I'm searching the docs

#

Probably the same as you are

cosmic agate
#

me too

supple thorn
#

Transil copying me i'm out

cosmic agate
#

wth