Skocz do zawartości

Rekomendowane odpowiedzi

Witam!

Dzisiaj wam zapraszam was na TUTORIAL DISCORD BOT!

 

 

1 Przygotowanie

1. Załóż konto na https://repl.it/

2. Dodaj nowy repl pacz 

3. Dodaj bota na stronie discorda (link https://discord.com/developers/applications ) pacz 

 

4. Dodaj bota do twojego serwera za pomocą linku który skopiowaliśmy

5. Połącz repla z discordem pacz 

2. Pisanie bota

Jak coś by wyświetlało jako błąd popacz tutaj czy to wypisałem:

Spoiler

!!! OBOWIĄZKOWE !!!
dodaj na początek kodu:
@client.event
async def on_ready():
  print('Zalogowano {0.user}'.format(client))
  
  
  
by dodawać komędy musisz napisać

@client.event

  msg = message.content

  
dalej dodajemy komędy

  if msg.startswith("COMAGRACZNAPISACBYTOAKTYWOWAC"):
    
    tutaj piszemy co chemy zrobić gdy gracz to napisze


wysyłanie wiadomosci:
piszemy
await message.channel.send("TOCONAPISZE")

warto dodać argumenty do komędy np.
  if msg.startswith("$alert"):
    value = msg.split("$alert ", 1)[1]
    await message.channel.send("ALERT!")
    await message.channel.send(value)
    await message.channel.send("ALERT!")

 

1. Pacz tylko XD 

 

 

2. Test bota 

 

Pełny projekt: 

Spoiler

import discord
import os
import requests
import json
import random



client = discord.Client()

sad_words = ["sad", "depressed", "unhappy", "angry", "miserable", "depressing"]

starter_encouragements = [
  "Cheer up!",
  "Hang in there.",
  "You are a great person / bot!"
]



def get_quote():
  response = requests.get("https://zenquotes.io/api/random")
  json_data = json.loads(response.text)
  quote = json_data[0]['q'] + " -" + json_data[0]['a']
  return(quote)

def update_encouragements(encouraging_message):
  if "encouragements" in db.keys():
    encouragements = db["encouragements"]
    encouragements.append(encouraging_message)
    db["encouragements"] = encouragements
  else:
    db["encouragements"] = [encouraging_message]

def delete_encouragment(index):
  encouragements = db["encouragements"]
  if len(encouragements) > index:
    del encouragements[index]
    db["encouragements"] = encouragements

@client.event
async def on_ready():
  print('Aktywowano {0.user}'.format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return

  msg = message.content

  if msg.startswith("$pomoc"):
    await message.channel.send("Pomoc")

  if msg.startswith("$pomocadmin"):
    await message.channel.send("Pomoc RoweX Dla Administratora")  
    await message.channel.send("1. $aktualizuj - aktualizuje bota do najnowsze wersji")
    await message.channel.send("1. $alert WIADOMOŚĆ - wysyła alert z wiadomoscią") 


  if msg.startswith("$aktualizuj"):
    await message.channel.send("Wersja Stabilna Jeszce Nie Wyszła!")
   

  if msg.startswith("$snapshot"):
    await message.channel.send("RoweX Snapshot 227.33   publiced by:@OskiBoskiLubiKabanoski and author")




  if msg.startswith("$alert"):
    value = msg.split("$alert ", 1)[1]
    await message.channel.send("ALERT!")
    await message.channel.send(value)
    await message.channel.send("ALERT!")

client.run(os.getenv('TOKEN'))

 

Dziękuję

Odnośnik do komentarza
https://skript.pl/temat/44599-bot-discord-tutorial-python/
Udostępnij na innych stronach

Ten "poradnik" to jakiś żart.

image.png

Nie, to nie jest obowiązkowe. To tylko po włączeniu bota pokazuje wiadomość w konsoli.

Nie robimy komend w sposób startswith. Discord.py ma od tego dekorator - @client.command().

Nie wspominam już nawet o ortografii, interpunkcji. Mimo to życzę powodzenia w nauce pythona :)

Odnośnik do komentarza
https://skript.pl/temat/44599-bot-discord-tutorial-python/#findComment-279966
Udostępnij na innych stronach

  • Szifter zablokował(a) ten temat
Nieaktywny
Ten temat został zamknięty. Brak możliwości dodania odpowiedzi.
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...