Files
bot.py
requirements.txt
Code
2 93
bot.py
import discord
from discord import app_commands
from discord.ext import commands
import os
from dotenv import load_dotenv
load_dotenv()
class PingView(discord.ui.View):
"""Persistent view with a single button to send the ad ping."""
def __init__(self):
super().__init__(timeout=None)
@discord.ui.button(
label="\U0001f4e2 Send Ping",
style=discord.ButtonStyle.danger,
custom_id="persistent_ping_btn",
)
async def ping_button(
self, interaction: discord.Interaction, button: discord.ui.Button
):
await self._send_ad(interaction)
async def _send_ad(self, interaction_or_ctx):
embed = discord.Embed(
description=(
"https://discord.gg/7g6yDvSXQr\n"
"# JOIN MSRP TODAY!\n"
"-NEW SERVER-\n"
"**-HIRING STAFF MEMBERS,HIGH RANK,-**"
)
)
embed.set_thumbnail(
url="https://cdn.discordapp.com/icons/1511500365374165002/0cf8e68368b29f8a41b8a89a067d869d.webp?size=2048"
)
if isinstance(interaction_or_ctx, discord.Interaction):
await interaction_or_ctx.response.send_message(
content="@everyone",
embed=embed,
allowed_mentions=discord.AllowedMentions(everyone=True),
)
else:
await interaction_or_ctx.send(
content="@everyone",
embed=embed,
allowed_mentions=discord.AllowedMentions(everyone=True),
)
class Bot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
super().__init__(command_prefix="!", intents=intents)
async def setup_hook(self):
self.add_view(PingView())
await self.tree.sync()
print(f"Synced commands for {self.user}")
bot = Bot()
@bot.event
async def on_ready():
print(f"Bot is ready! Logged in as {bot.user}")
@bot.tree.command(
name="ad",
description="Send the MSRP advertisement ping",
)
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def ad_command(interaction: discord.Interaction):
"""Slash command that shows a button; the button sends the ad."""
view = PingView()
await interaction.response.send_message(
"Click the button below to send the ad:",
view=view,
ephemeral=True,
)
bot.run(os.getenv("DISCORD_TOKEN"))