Kodlar
DM Duyuru.py
DM Duyuru.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import discord
from discord.ext import commands
import asyncio

TOKEN = "BOT TOKENIN BURAYA"

class MyBot(commands.Bot):
    def __init__(self):
        intents = discord.Intents.default()
        intents.members = True
        intents.message_content = True
        super().__init__(command_prefix="b!", intents=intents)

    async def setup_hook(self):
        print(f"Bot hazır.")

bot = MyBot()

@bot.event
async def on_ready():
    print(f"{bot.user} olarak giriş yapıldı!")

@bot.command(name="ping")
async def ping(ctx):
    await ctx.send(f"🏓 Pong! `{round(bot.latency * 1000)}ms`")

@bot.command(name="dmduyuru")
@commands.has_permissions(administrator=True)
async def dmduyur(ctx, *, mesaj: str):
    await ctx.send("Duyuru gönderimi başlatıldı...", delete_after=5)
    
    basarili = 0
    basarisiz = 0
    
    for member in ctx.guild.members:
        if member.bot:
            continue
            
        try:
            embed = discord.Embed(
                title="📢 Sunucu Duyurusu",
                description=mesaj,
                color=discord.Color.blurple()
            )
            embed.set_author(
                name="BlueKey",
                icon_url=ctx.guild.icon.url
            )
            embed.set_footer(text="BlueKey Sunucusu")
            
            await member.send(embed=embed)
            basarili += 1
            await asyncio.sleep(0.3)
        except discord.Forbidden:
            basarisiz += 1
        except Exception as e:
            print(f"Hata oluştu ({member.name}): {e}")
            basarisiz += 1

    await ctx.send(
        f"✅ İşlem tamamlandı!\n\n"
        f"**Başarılı:** {basarili}\n"
        f"**Başarısız (DM Kapalı):** {basarisiz}"
    )

@dmduyur.error
async def dmduyur_error(ctx, error):
    if isinstance(error, commands.MissingPermissions):
        await ctx.send("Bu komutu kullanmak için `Yönetici` yetkisine sahip olmalısın!")

bot.run(TOKEN)
2Beğeni
3Görüntülenme
Kod Bilgisi
DilPython
Satır71
Karakter2,002
Tarih01.05.2026
Açıklama

Sunucudaki herkese belirttiğin texti dm atar, başarısız sayını vb. bildirir.

Etiketler
#dmduyuru