-
Notifications
You must be signed in to change notification settings - Fork 1
/
webhook_man_bot.py
51 lines (42 loc) · 1.35 KB
/
webhook_man_bot.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
import discord
from discord.ext import commands
import faker
from config_loader import Config
"""
add a file named .env in the same directory as this file
with the following content:
TOKEN=[your_token_here]
BOT USAGE:
_gen [amount] - Generates a webhook in the current channel
_rem - Removes all webhooks in the current channel
"""
TOKEN = Config(bot_token_filename=".conf/bot_token").bot_token
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='_', intents=intents)
fake = faker.Faker(['zh_TW', 'ja_JP', 'ko_KR', 'en_US', 'en_GB'])
@bot.event
async def on_ready():
print(f'{bot.user} has connected to Discord!')
@bot.command()
async def gen(ctx, amount: int=None):
channel = ctx.channel
urls = []
if amount is None:
webhook = await channel.create_webhook(name=fake.name())
urls.append(webhook.url)
else:
for i in range(int(amount)):
webhook = await channel.create_webhook(name=fake.name())
urls.append(webhook.url)
await ctx.send(
f'Generated {amount} webhook(s) in {channel.mention}\n'
+ '\n'.join(urls)
)
@bot.command()
async def rem(ctx):
channel = ctx.channel
webhooks = await channel.webhooks()
for webhook in webhooks:
await webhook.delete()
await ctx.send(f'Removed all webhooks in {channel.mention}')
bot.run(TOKEN)