Discord Botu Komutlara Tepki Vermiyor

HAYYAMMM

Centipat
Katılım
18 Ekim 2021
Mesajlar
12
Daha fazla  
Cinsiyet
Erkek
Herkese merhabalar, Dün akşam ChatGPT yardımıyla, Python kullanarak PyCharm üzerinden bir Discord Botu oluşturdum, kodu çalıştırdım bir hata almadım, botum şuan Discord üzerinde online gözüküyor ancak istediğim komuta bir türlü teki vermiyor, ilgili kodları aşağıya koyuyorum

1.PNG

2.PNG


Kodun yazılı hali:

Kod:
import discord
import requests
from discord.ext import commands

# Create a new Intents object
intents = discord.Intents.default()

# Enable the necessary privileged intents
intents.guilds = True
intents.members = True
intents.messages = True

# Instantiate the bot object with the intents parameter
bot = commands.Bot(command_prefix='$', intents=intents)

@bot.command()
async def node(ctx, *, node_id):
# Extract node ID from user input
    node_id = node_id.split('=')[1]

# Send a request to Celestia API to get node information
    url = f'https://api.celestia.org/node/{node_id}/status'
    response = requests.get(url)

# Check if node information is retrieved successfully
    if response.status_code != 200:
await ctx.send('Node information could not be retrieved.')
return

    # Parse node information from response
    node_info = response.json()
node_status = node_info['status']

# Format and send node information as a message to Discord channel
    message = (f'Head: {node_status["head"]}\n'
               f'Total Sampled Headers (DAS): {node_status["das_count"]}\n'
               f'Node Start Time: {node_status["node_start_time"]}\n'
               f'PayForBlob Count: {node_status["pfob_count"]}\n'
               f'Last PayForBlob: {node_status["last_pfob"]}\n'
               f'Last Sampled Time: {node_status["last_sampled_time"]}\n'
               f'Last Restart Time: {node_status["last_restart_time"]}\n'
               f'Node Uptime: {node_status["node_uptime"]}\n'
               f'Uptime Score: {node_status["uptime_score"]}')
 await ctx.send(message)

bot.run('MTA5NTQzOTYzMTYyMjg3NzIzNg.G69i8O.Dba18_gaONI8fU9AHT64uRNey_W0ph1bzJfK8U')


Özetle botun amacını anlatayım: Bu site üzerindeki validatörlerin anlık bilgilerinin çıktısını versin istiyorum, örnek olarak bu linkteki gibi " Head: , Total Sampled Headers (DAS): Node Start Time: PayForBlob Count: Last PayForBlob: Last Sampled Time: Last Restart Time: Node Uptime: Uptime Score: gibi değerleri $node_id= ID formatında döndürmesini istiyorum. Ancak discord üzerinde belirtilen formatı yazınca hiçbir çıktı alamıyorum.
Ekran Alıntısı.PNG


Discord Developer alanında da bütün intents'leri açtım bota bot ve administrator yetkisini verdim ancak nafile, yine olmuyor. Tek istediğim bu minvalde bir çıktı almak.
Technopat Developerlarına güveniyor, yardımlarınızı bekliyorum.
image.png
 
Komutu yanlış yazıyorsun ki.
$node fkjasljfakskjljf gibi bir komut hazırlamışsın.
Prefixten sonra verdiğin string botun algılayacağı komut olmalı daha sonrasında space basıp parametre vermelisin. Parametreyi de parametre=asdf gibi vermeyeceksin.
prefixkomut parametre_değeri
Ayrıca bot tokenini paylaşmışsın değiştirmeni şiddetle öneriyorum.

Düzenleme: İlk parametreyi parametre=asdf vermeyeceksin demiştim ancak kodunun içinde bu böyle değilmiş. Komutunu şu şekilde kullan:
$node node_id=dkasjfklasjd
 
Bu kodlarda birkaç hata var. İlk olarak, async def node fonksiyonu doğru bir şekilde girintili değil, yani if bloğu ve altındaki kodlar doğru bir şekilde girintili değil. Ayrıca, return ifadesinden önceki await anahtar kelimesi de yanlış girintili. Ayrıca, botun anahtarını bot.run çağrısı içinde açıkça belirtmek yerine, bunu bir çevresel değişken olarak tanımlamak daha güvenlidir. Son olarak, kullanıcının girdiği node_idyi işlemek için yanlış bir yöntem kullanıyorsunuz. Bunun yerine, bunu daha güvenli bir şekilde işlemek için bir try-except bloğu kullanabilirsiniz. Aşağıda düzeltilmiş kodlar var bir de bunu deneyin:
Kod:
import os
import discord
import requests
from discord.ext import commands

# Create a new Intents object
intents = discord.Intents.default()

# Enable the necessary privileged intents
intents.guilds = True
intents.members = True
intents.messages = True

# Instantiate the bot object with the intents parameter
bot = commands.Bot(command_prefix='$', intents=intents)

@bot.command()
async def node(ctx, *, node_id):
    # Extract node ID from user input
    try:
        node_id = int(node_id.split('=')[1])
    except:
        await ctx.send('Invalid node ID.')
        return

    # Send a request to Celestia API to get node information
    url = f'https://api.celestia.org/node/{node_id}/status'
    response = requests.get(url)

    # Check if node information is retrieved successfully
    if response.status_code != 200:
        await ctx.send('Node information could not be retrieved.')
        return

    # Parse node information from response
    node_info = response.json()
    node_status = node_info['status']

    # Format and send node information as a message to Discord channel
    message = (f'Head: {node_status["head"]}\n'
               f'Total Sampled Headers (DAS): {node_status["das_count"]}\n'
               f'Node Start Time: {node_status["node_start_time"]}\n'
               f'PayForBlob Count: {node_status["pfob_count"]}\n'
               f'Last PayForBlob: {node_status["last_pfob"]}\n'
               f'Last Sampled Time: {node_status["last_sampled_time"]}\n'
               f'Last Restart Time: {node_status["last_restart_time"]}\n'
               f'Node Uptime: {node_status["node_uptime"]}\n'
               f'Uptime Score: {node_status["uptime_score"]}')
    await ctx.send(message)

bot.run(os.environ['DISCORD_TOKEN'])
 

Yeni konular

Geri
Yukarı