Discord Thread Reply

Hello, is anyone know why this DISCORD bot don’t working? It should be work like this:
Someone is creating new thread on DISCORD FORUM and this bot should text in his post like “Hello Thanks for open this thread” but he wasn’t.
anyone know why?

  • Something Like this, someone is creating new thread on forum and discord bot should automaticly text on it.

I have this code:


import discord
from discord.ext import commands
import logging
import logging.handlers

# Konfiguracja dzienników
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
logging.getLogger('discord.http').setLevel(logging.INFO)

handler = logging.handlers.RotatingFileHandler(
    filename='discord.log',
    encoding='utf-8',
    maxBytes=32 * 1024 * 1024,  # 32 MiB
    backupCount=5,  # Rotate through 5 files
)
dt_fmt = '%Y-%m-%d %H:%M:%S'
formatter = logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', dt_fmt, style='{')
handler.setFormatter(formatter)
logger.addHandler(handler)

# Konfiguracja bota
prefix = "!" 
TOKEN = "x"

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

# Funkcja do wysyłania wiadomości
async def send_message(channel_id, message):
    channel = bot.get_channel(channel_id)
    await channel.send(message)

# Zdarzenie wywoływane po utworzeniu wątku
@bot.event
async def on_thread_create(thread):
    await thread.parent.send("Thread created...")

# Komenda do wyłączania bota
@bot.command()
async def shutdown(ctx):
    await ctx.send("Bot zostaje wyłączony...")
    await bot.close()

# Uruchomienie bota
bot.run(TOKEN)

but bot won’t text on new created thread. Is anyone know?
There isn’t any debug error

Co prawda nie znam się na botach Discorda, ale jak ta funkcja jest rejestrowana do wysyłania? W innych widzę dekoratory @bot.coś_tam a tu nic O_o

…Are the decorator names actually localized like this?

You mean dekoratory == “decorators” in Polish? Yes, they are :slight_smile:

No, I meant: can you really write @bot.coś_tam in the source code, rather than being expected to use an English name for… whatever coś_tam means?

Well, I once tested that Python “gets” variable, function, class etc. names written in any other language that English very well :smiley: Namely everything that is not required by Python grammar to be an English word (like, keywords) can use any characters that is considered a “word” characters.

Of course if one work with code that is read by an international team, then we use English language :wink:

Oh, and by the way: “coś tam” means “whatever”. I said to OP that there is no “whatever” decorator in the quoted function :slight_smile:

Oh, I thought you meant that there was something specific in the API with that name, which is why I was surprised. For that to work, the developers would have to alias the name.

w.g chatu gpt tak powinno być ;d
nie mam pomyslu juz dlaczego to nie działa.

Jak to ustaliliśmy na tym forum, Chat GPT to raczej kiepski nauczyciel :wink: Raczej bym posiłkował się oficjalną dokumentacją tej biblioteki. Jak powiedziałem, nie robiłem nigdy bota do Discorda, ale ten kawałek kodu wydał mi się mocno podejrzany.

Ok, poszperałem tu i ówdzie i mnie się wydaje, że to powinno tak “zabrzmieć”:

# Konfiguracja bota

TOKEN = "TOKEN_BOTA" #sprawdź w ustawieniach!

bot = commands.Bot(intents=discord.Intents.all())

# Zdarzenie wywoływane po utworzeniu wątku
@bot.event
async def on_thread_create(thread):
    await thread.send("Utworzyłeś wątek! :D")


# Uruchomienie bota
bot.run(TOKEN)

Czyli potrzebna była jedna funkcja a nie trzy :slight_smile:

Dobra, przetestowałem ten kod, ale dalej nic. Zero błędów w konsoli, a na wątku dalej nic się nie pojawia

Hmm, możliwe więc, że bot żąda od serwera robienie czegoś czego mu nie przyzwolono.

  • Sprawdź w ustawieniach bota, czy bot ma uprawnienia do wysyłania wiadomości na wątkach.
  • Być może instrukcja intents=discord.Intents.all() próbuje pobrać za duże uprawnienia. Spróbuj może zamienić to na intents=discord.Intents(guilds=True).

Please note that this is an English-language forum; please stick to English so that everyone here can participate.

Unfortunately, that didn’t help either

1 Like

Sorry, I forgot myself about this :blush:

To recap for others: in this Discord Thread Reply - #10 by FelixLeg post I recommended a new code to send a message to a newly made thread. Unfortunately, it still doesn’t send that message, which in the second post I wrote my doubts about if the bot was given the right set of permissions. But Kacper says it is still nothing.

If one can add something to the discussion, feel free to do so! I in the meantime am going to dig deeper in the Discord.py documentation :slight_smile:

1 Like

I’m still digging but for now a temporary idea: please, put in on_thread_create(...) a simple print like print("On thread create was executed") and check if that line is print on the console. If it is, then the problem lies in thread.send(...), if not then we have to check @bot.event.

It will help me to find the culprit.