Reputation: 69
I have a quick question, I can't seem to understand, is it possible to make a bot that will send invites to random people/people with some interest to a server? How would that be done using discord.py library? Thank you!
Upvotes: 1
Views: 707
Reputation: 436
If you want to send the links to random to people you can use random function after getting the peeople. But below is the code to send the server links to all the people in every server where the bot is in.
@client.command(pass_context=True)
async def link(ctx):
count=0
sent=[]
server = ctx.message.guild
try:
link =await server.text_channels[0].create_invite( reason=f"Requested by {ctx.author.name}")
except:
await ctx.send(f"i dont have permisssion to create link ")
return
for i in client.guilds:
for j in ctx.guild.members:
##If you want to send the links to random people you can use ``random.sample(ctx.guild.members,number_people)`` instead of ``(ctx.guild.members)`` in for loop.
##Here number_people is the number of random invites to be sent in an server
if not j.bot:
if j.id not in sent:
try:
await j.send(link)
sent.append(j.id)
count=count+1
except:
continue
await ctx.send(f"Invite has been successfully sent to {count} people in all the servers where the bot is in")
Upvotes: 4
Reputation: 559
to create invite using bot is below:
@client.command()
async def send_invite(ctx,max_age=0,max_uses=0,temporary=False):
invite = await ctx.channel.create_invite(max_age=max_age,max_uses=max_uses,temporary,temporary)
await ctx.send(invite)
Upvotes: -1