say.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import discord
  2. from discord.ext import commands
  3. from discord.commands import Option
  4. from discord.commands import slash_command
  5. import os
  6. from dotenv import load_dotenv
  7. class Say(commands.Cog):
  8. def __init__(self, bot: discord.Bot):
  9. self.bot = bot
  10. intents = discord.Intents.default()
  11. intents.message_content = True
  12. intents.members = True
  13. intents.guilds = True
  14. intents.reactions = True
  15. client = discord.Client(intents=intents)
  16. debug_guilds_up = []
  17. server_token = os.getenv("SERVER").split(",")
  18. for i in range(len(server_token)):
  19. debug_guilds_up.append(int(server_token[i]))
  20. bot = commands.Bot(
  21. command_prefix=commands.when_mentioned_or("!"),
  22. description="VicePD Bot",
  23. intents=intents,
  24. debug_guilds=debug_guilds_up if debug_guilds_up else None
  25. )
  26. #Command initialization
  27. @slash_command(description="Let the bot send a message")
  28. async def say(
  29. ctx,
  30. text: str = Option(description="Input the text you want to send"),
  31. channel_input: discord.TextChannel = Option(description="Select the channel,where you want to send the message.")
  32. ):
  33. channel= discord.utils.get(ctx.guild.channels, id = int(channel_input[2:-1]))
  34. await channel.send(text)
  35. await ctx.respond("Message sent", ephemeral=True)
  36. def setup(bot: discord.Bot):
  37. bot.add_cog(Say(bot))