Reputation: 422
Am i able to get a list of all webhook URLs in a discord server using discord.py or another Discord bot python library? Sorry that this is so short im not sure what other information i could provide for my question.
I have also tried the following.
import discord
client = command.Bot()
@client.event
async def on_message(message):
message.content.lower()
if message.author == client.user:
return
if message.content.startswith("webhook"):
async def urls(ctx):
@client.command()
async def urls(ctx):
content = "\n".join([f"{w.name} - {w.url}" for w in await ctx.guild.webhooks()])
await ctx.send(content)
client.run('tokennumber')
Upvotes: 3
Views: 4812
Reputation: 6944
Here's an example command using list comprehension that would return the link for each webhook:
@bot.command()
async def urls(ctx):
content = "\n".join([f"{w.name} - {w.url}" for w in await ctx.guild.webhooks()])
await ctx.send(content)
Here's what the list comprehension is doing:
@bot.command()
async def urls(ctx):
wlist = []
for w in await ctx.guild.webhooks():
wlist.append(f"{w.name} - {w.url}")
content = "\n".join(wlist)
await ctx.send(content)
Post-edit:
Using your on_message()
event:
import discord
client = commands.Bot() # add command_prefix kwarg if you plan on using cmd decorators
@client.event
async def on_message(message):
message.content.lower()
if message.author == client.user:
return
if message.content.startswith("webhook"):
content = "\n".join([f"{w.name} - {w.url}" for w in await message.guild.webhooks()])
await message.channel.send(content)
client.run('token')
If you don't want to print out each webhooks' name, then you can just join each url instead:
content = "\n".join([w.url for w in await message.guild.webhooks()])
References:
Guild.webhooks()
- coroutine
, therefore needs to be await
ed.Webhook.name
Webhook.url
Upvotes: 2