#๐Ÿ”’ Send Dm Bot Discord

71 messages ยท Page 1 of 1 (latest)

wooden oasis
#

i am new to discord.py so here is my code,
but it always says can't find the id (sorry lots of typos in the code)

user = bot.get_user(user_id)
    if user is None:
        return await ctx.reply("Something's wrong, I can't find the id!")
    try:
        await user.dm_channel.send("tes send")
    except discord.Forbidden:
        await ctx.reply("I can't send a DM to that user, maybe try the manual method?")```
outer gobletBOT
#

@wooden oasis

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

crystal egret
#

show the whole command

wooden oasis
# crystal egret show the whole command
@bot.command()
async def reply(ctx, *, message: str = None):
    admin = await get_admin(ctx.author.id)
    print(f"[Owner | main] admin status for {ctx.author.id}:", admin)
    if not admin:
        return await ctx.reply(
            "Sorry, this command is only available for admins", delete_after=5
        )
    if message is None:
        return await ctx.reply("Please provide a message.", delete_after=5)

    split_message = message.split(maxsplit=1)  # Split message into two parts
    user_id = split_message[0]  # First part is the user ID
    if len(split_message) > 1:
        message_content = split_message[1]  # Second part is the message content
    else:
        message_content = ""  # If there's no message content provided
    print("User ID:", user_id)
    print("Message:", message_content)
    user = bot.get_user(user_id)
    if user is None:
        return await ctx.reply("Somting Went Wrong, i cat finde the id!")
    try:
        await user.dm_channel.send("tes send")
    except discord.Forbidden:
        await ctx.reply("i couldt send dm to that user, maybe try manual way?")```
oblique pecan
#

theres quite a bit wrong with this here

#

this line admin = await get_admin(ctx.author.id) will consider anybody that runs the command as "admin" my mistake

#

then assuming the user_id is even in the message content that you're splitting, it will b e a string, get_user is expecting an int

wooden oasis
oblique pecan
#

you should be using bot.get_member instead of bot.get_user, and then there is no dm_channel when DMing a user, it would just be user.send

wooden oasis
#

ok thanks man i will try that

oblique pecan
oblique pecan
wooden oasis
#

ok

oblique pecan
#

get user will technically still work, but generally you want to be working with a Member object rather than a User object

wooden oasis
#

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

#

not get_all_members?

oblique pecan
#

oh sorry its guild.get_member

wooden oasis
#

because what's here is just get_all_members

#

ah ok

oblique pecan
#

I'd be doing ctx.guild.get_member(int(user_id))

wooden oasis
#

okk

oblique pecan
#

and remember to remove the dm_channel from user.send

wooden oasis
oblique pecan
#

yea that should be fine

#

that error happened after you changed it?

wooden oasis
#

yes

oblique pecan
#

hm yeah thats weird

#

try adding a print(user) after you get the user/member object

oblique pecan
#

the user you're trying to get is in the same guild as the bot?

wooden oasis
#

yes

#

thats is my id

#

just for test

oblique pecan
#

you have intents?

#

Intents.members = True

wooden oasis
#

like that?

oblique pecan
#

members is a separate intent from message_content and default

#
Intents.members = True
Intents.message_content = True```
wooden oasis
#

ok i will try

#

yeah its fixsed but now erorr 400 bad request sad

#

Cannot send messages to this user

oblique pecan
#

make sure you accept DMs in at least one server you share with the bot

#

it'll be in your privacy settings for the server

wooden oasis
#

ah yeah im forget

untold shadow
#

hi

wooden oasis
oblique pecan
#

usually discord.Forbidden occurs when you have blocked the bot

#

you enabled DMs for the server in common?

wooden oasis
untold shadow
#
from bs4 import BeautifulSoup
import time

# Function to log in to Roblox
def login(username, password):
    login_url = "https://www.roblox.com/newlogin"
    session = requests.Session()
    login_data = {
        "username": username,
        "password": password
    }
    session.post(login_url, data=login_data)
    return session

# Function to get free limited items
def get_free_limited_items(session):
    items_url = "https://www.roblox.com/catalog/?Category=13&Subcategory=16"
    response = session.get(items_url)
    soup = BeautifulSoup(response.text, "html.parser")
    item_containers = soup.find_all("li", class_="item-card")
    free_limited_items = []
    for item in item_containers:
        item_name = item.find("a", class_="item-card-name").text.strip()
        item_link = item.find("a", class_="item-card-link")["href"]
        if "Limited" in item.find("div", class_="item-card-status").text:
            free_limited_items.append({"name": item_name, "link": item_link})
    return free_limited_items

# Function to claim free items
def claim_items(session, items):
    for item in items:
        response = session.get(item["link"])
        # Implement logic to claim item (e.g., clicking buttons, submitting forms)
        print(f"Claimed item: {item['name']}")
        time.sleep(1)  # Add a delay to avoid spamming requests


def check_and_claim(username, password):
    session = login(username, password)
    while True:
        free_limited_items = get_free_limited_items(session)
        claim_items(session, free_limited_items)
        time.sleep(10)
        if should_stop():  # Check if the script should stop
            break

# Function to determine whether the script should stop
def should_stop():
    return False

# Example usage
if __name__ == "__main__":
    username = "username"
    password = "password"

    check_and_claim(username, password)
#

can u told me why my code arent working

wooden oasis
#

@oblique pecan hey its working thanks

oblique pecan
# wooden oasis this one right ?

Not quite, that looks like the DM settings from your account settings, it wont be applied to your existing servers unless you turn it off then back on and accept the "apply to all servers pop-up"

oblique pecan
oblique pecan
untold shadow
#

ok

wooden oasis
oblique pecan
#

no problem, if you're in the discord.py discord try out the search function there, it works well since somebody has always had the same error at some point and its been solved

#

beats google tbh

wooden oasis
#

XD yeah

untold shadow
#

cant creat

#

thread

oblique pecan
#

you might not be allowed since you're new here though, I guess?

untold shadow
#

yh

outer gobletBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.