Çözüldü Python Discord.py "Sa" yazınca "As" yazan komut

Bu konu çözüldü olarak işaretlenmiştir. Çözülmediğini düşünüyorsanız konuyu rapor edebilirsiniz.

Lykoss

Decapat
Katılım
23 Mayıs 2021
Mesajlar
957
Çözümler
6
Daha fazla  
Cinsiyet
Erkek
Meslek
Öğrenci
[CODE lang="python" title="A"]import discord
from discord.ext import commands
import random
from webserver import keep_alive
import saas
keep_alive()
Bot = commands.Bot(command_prefix='!m ')

@Bot.event
async def on_ready():
print("Bot çalışıyor." + str(Bot.user))
#------------------------------------------------------------------------

@Bot.command()
async def yardım(msg):
await msg.send('YARDIM')

@Bot.command()
async def musty(msg):
await msg.send('Merhaba ben MusTy')

#temizleme
@Bot.command()
async def temizle(ctx,amount=15):
await ctx.channel.purge(limit=amount)

#zaratma
@Bot.command()
async def zar(msg):
zar = random.randint(1,6)
await msg.send("Zar {} geldi.".format(zar))

#Ders programı
@Bot.command()
async def dersprogramı(msg):
await msg.send('A')

#Ödevler
@Bot.command()
async def ödevler(msg):
await msg.send('A')

#------------------------------------------------------------------------
Bot.run('(TOKEN)')
[/CODE]



[CODE lang="python" title="Sa-as"]import discord
from discord.ext.commands import Bot

TOKEN = "Sansür"

client = discord.Client()
bot = Bot(command_prefix="!m ")

@bot.event
async def on_ready():
print("Bot Hazır " + str(bot.user))


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

if message.content == ("Sa"):
await message.channel.send("as")

if message.content == ("sa"):
await message.channel.send("as")

bot.run(TOKEN)
[/CODE]
Sınıf Sunucumuz için bir bot yapmıştım. Kullanıcı Sa yazınca As yazmasını istiyorum. Kendim yaptığımda !m komutları çalışmıyor. İkisi de nasıl çalışabilir?
 
Son düzenleme:
Çözüm
Her action'dan sonra break kullanmayın lütfen.
Python:
import discord
from discord.ext  import commands

client = discord.Client()
Bot = commands.Bot(command_prefix='!m ')
selam = ["selam","Selam","slm","SELAM"]


@Bot.event
async def on_ready():
 print("Bot çalışıyor." + str(Bot.user))
#------------------------------------------------------------------------

@Bot.event
async def on_message(message):
    if message.author.id == Bot.user.id:
        return
    if message.content in selam:
        await message.channel.send("Selam Gardaşım")
    await Bot.process_commands(message)


Bot.run("")

Şu kullandığınız for döngüsünü de anlayamadım ne gerek var. Python'da listeyi if a in list şeklinde kontrol edebiliyorsunuz.
Ha eğer mesaj içeriğinin herhangi bir yerinde selam bulunmasını kontrol etmek istiyorsan
Split = msg.content.split() kullan.
break'i if bloğunun içerisine yazın.
Python:
for i in selam:
 if i in message.content:
 await message.channel.send("Selam.")
 break

Sizin attığınız gibi yazınca döngü kırılmıyor.

Python:
@Bot.event
async def on_message(message):
   
    for i in selam:
      if i in message.content:
        await message.channel.send("Selam.")
      break

Böyle de aynı şey oluyor.Yani "slm" ya da "Selam" yazınca cevap gelmiyor.
 
[CODE lang="python" title="KOD-TÜMÜ"]import discord
from discord.ext import commands
import random
from webserver import keep_alive


client = discord.Client()
keep_alive()
Bot = commands.Bot(command_prefix='!m ')
selam = ["selam","Selam","slm","SELAM"]


@Bot.event
async def on_ready():
print("Bot çalışıyor." + str(Bot.user))
#------------------------------------------------------------------------
@Bot.command()
async def yardım(msg):
await msg.send('A.')

@Bot.event
async def on_message(message):



if message.content.upper() == ("MUSTY"):
await message.channel.send("A")

if message.content.upper() == ("GÜNAYDIN"):
await message.channel.send("Sabah şerifleriniz hayrolsun.")

if message.content.lower() == ("iyi geceler"):
await message.channel.send("İyi geceler,tatlı rüyalar.")

if message.content.upper() == ("SA"):
await message.channel.send("Aleyküm selam hoşgeldiniz.")
await Bot.process_commands(message)

for i in selam:
if i in message.content:
await message.channel.send("Selam.")
break

@Bot.command()
async def musty(msg):
await msg.send('Merhaba ben MusTy')

#temizleme
@Bot.command()
async def temizle(ctx,amount=15):
await ctx.channel.purge(limit=amount)

#zaratma
@Bot.command()
async def zar(msg):
zar = random.randint(1,6)
await msg.send("Zar {} geldi.".format(zar))

#Ders programı
@Bot.command()
async def dersprogramı(msg):
await msg.send('.jpg')

#Ödevler
@Bot.command()
async def ödevler(msg):
await msg.send('A')

Bot.run("TOKEN")[/CODE]
SA yazınca:
1648060947964.png
 
On Message eventinin son kısmına bu kodu eklemeniz yeterliydi.

[CODE lang="python" title="Örnek Kod"]@client.event
async def on_message(message):
#Sa as mesajlarınız vb
#En sonada alttaki.
await client.process_commands(message)[/CODE]

NOT: Kusura bakmayın galiba bu sorunu çözmüşsünüz...
 
Python:
@Bot.event
async def on_message(message):
    if message.content.upper() == ("MUSTY"):
        await message.channel.send("A")
    if message.content.upper() == ("GÜNAYDIN"):
      await message.channel.send("Sabah şerifleriniz hayrolsun.")
    if message.content.lower() == ("iyi geceler"):
      await message.channel.send("İyi geceler,tatlı rüyalar.")
    for i in selam:
      if i in message.content:
         await message.channel.send("Selam.")
      break
    await Bot.process_commands(message)
Olarak yazmayı dener misin ?
NOT: Kusura bakmayın galiba bu sorunu çözmüşsünüz...
Estağfurullah. @Lykoss yaşadığı her sorunu sırayla attığından kodun tamamına da hakim olmadığımdan söylediğim her yeni kodu bir alt satıra atmış. Doğrusunun sizin dediğiniz gibi olduğunu farkedip düzenleyeceğini düşünüyorum.
 
Python:
import discord
from discord.ext  import commands
import random
from webserver import keep_alive


client = discord.Client()
keep_alive()
Bot = commands.Bot(command_prefix='!m ')
selam = ["selam","Selam","slm","SELAM"]


@Bot.event
async def on_ready():
 print("Bot çalışıyor." + str(Bot.user))
#------------------------------------------------------------------------
@Bot.command()
async def yardım(msg):
  await msg.send('.')

@Bot.event
async def on_message(message):
    if message.content.upper() == ("MUSTY"):
        await message.channel.send(".")
    if message.content.upper() == ("GÜNAYDIN"):
      await message.channel.send("Sabah şerifleriniz hayrolsun.")
    
    if message.content.lower() == ("iyi geceler"):
      await message.channel.send("İyi geceler,tatlı rüyalar.")
 
    if message.content.upper() == ("SA"):
        await message.channel.send("Aleyküm selam hoşgeldiniz.")

    for i in selam:
      if i in message.content:
        await message.channel.send("Selam")
      break
    await Bot.process_commands(message)
    

@Bot.command()
async def musty(msg):
  await msg.send('Merhaba ben MusTy')

#temizleme
@Bot.command()
async def temizle(ctx,amount=15):
    await ctx.channel.purge(limit=amount)

#zaratma
@Bot.command()
async def zar(msg):
  zar = random.randint(1,6)
  await msg.send("Zar {} geldi.".format(zar))

#Ders programı
@Bot.command()
async def dersprogramı(msg):
  await msg.send('.jpg')

#Ödevler
@Bot.command()
async def ödevler(msg):
  await msg.send('.')

Bot.run(".")
Son hali bu.Sorun hala devam ediyor.
 

Technopat Haberler

Yeni konular

Geri
Yukarı