Skip to content

Instantly share code, notes, and snippets.

@4Kaylum
Created September 6, 2019 22:25
Show Gist options
  • Save 4Kaylum/823b2a8b5faa9c174e1644802978dc0d to your computer and use it in GitHub Desktop.
Save 4Kaylum/823b2a8b5faa9c174e1644802978dc0d to your computer and use it in GitHub Desktop.
A cog that pings everyone on the server every 10 seconds
"""Make a bot that pings everyone on the server every 10 seconds"""
import discord
from discord.ext import commands
from discord.ext import tasks
from cogs import utils
class EveryonePing(utils.Cog):
def __init__(self, bot:utils.CustomBot):
super().__init__(bot)
self.channels = {} # guild_id: TextChannel
self.ping_everyone.start()
def cog_unload(self):
self.ping_everyone.cancel()
@tasks.loop(seconds=10)
async def ping_everyone(self):
"""Ping everyeonesdfkljhs"""
for channel in self.channels.values():
try:
await channel.send("@everyone time to get your bread")
except discord.Forbidden:
pass
@commands.command()
@commands.has_permissions(manage_guild=True)
async def everyoneset(self, ctx:commands.Context, channel:discord.TextChannel=None):
"""Sets the channel that eveyrone'll be pinged in"""
channel = channel or ctx.channel
if ctx.guild is None:
await ctx.send("You can't run this command in DMs.")
return
if not channel.permissions_for(ctx.guild.me).send_messages:
await ctx.send("I don't have permissions to send messages to that channel")
return
self.channels[ctx.guild] = channel
await ctx.send("Channel set.")
def setup(bot:utils.CustomBot):
x = EveryonePing(bot)
bot.add_cog(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment