import os
import discord
from discord.ext import commands
from discord import app_commands
from discord.ui import Select, View
token = os.getenv("DISCORD_TOKEN")
bot = commands.Bot(command_prefix='/', intents=discord.Intents.all())
class ChannelSelect(Select):
def __init__(self, channels, message):
options = [
discord.SelectOption(label=channel.name, value=str(channel.id))
for channel in channels
]
super().__init__(placeholder="Выберите канал...",
min_values=1, max_values=1, options=options)
self.message = message
async def callback(self, interaction: discord.Interaction):
channel_id = int(self.values[0])
channel = bot.get_channel(channel_id)
if channel:
await channel.send(self.message)
await interaction.response.send_message(f"Сообщение отправлено в {channel.mention}", ephemeral=True)
else:
await interaction.response.send_message("Канал не найден.", ephemeral=True)
@bot.tree.command(name="setwelcome")
@app_commands.describe(message="Сообщение, которое будет присылаться в данный канал({member.name} - зашедший человек)")
async def setwelcome(interaction: discord.Interaction, message: str):
guild = interaction.guild
text_channels = guild.text_channels
view = View()
view.add_item(ChannelSelect(text_channels, message))
await interaction.response.send_message("Выберите канал для отправки сообщения:", view=view, ephemeral=True)
@bot.event
async def on_ready():
await bot.tree.sync()
print(f'Мы вошли как {bot.user}')
bot.run(token)
код: