Discord.py embeded message user reactions - python

I've been trying to solve this for a couple days with no solution. I want my discord bot to be able to buy digital items, and to buy them I have made a confirmation message and a system where you react to confirm with a 60 seconds timeout with a code I found online.
The problem with that code is it doesnt take into account the message the user reacted, so for example if the user sends two messages and confirms one, they both get executed, also, I can't add another icon like a cancel one. It is pretty important since this is an important function for the bot to work.
Also, making a on_reaction_add function is not viable since I would like my bot to run in various servers and channels at the same time with diferent users sending commands.
#client.event
async def on_message(message):
channel = message.channel
embedVar2 = discord.Embed(title="Item buying", description="<#"+ str(message.author.id) +"> Are you sure you want to buy " + str(conditions[1]) + " quantity of " + str(conditions[0]), color = 0x9A9B9D)
embedVar2.add_field(name="\u200b", value= "It will cost $" + str(price) + " you will have $" + str(endbal) + " remaining \nReact with ✅ to confirm", inline=False)
await confirm_message.add_reaction("✅") #add a reaction for the user to understand he has to react
def check(reaction, user): #checks if user has reacted
return user == message.author and str(reaction.emoji) == '✅'
try: #waits if it doest get timeout error
reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check) #calls for function check defined prev
except asyncio.TimeoutError: #if timeout throws error:
embedVar5 = discord.Embed(title="Money transfer", description="<#"+ str(message.author.id) +"> Are you sure you want to buy " + str(conditions[1]) + " quantity of " + str(conditions[0]), color = 0xFF0A26)
embedVar5.add_field(name="\u200b", value= "It would have cost $" + str(price) + " you would have had $" + str(endbal) + " remaining \nTransaction canceled", inline=False)
await confirm_message.edit(embed = embedVar5) #message edit to canceled
return
else: #if user reacted before timeout
embedVar4 = discord.Embed(title="Money transfer", description="<#"+ str(message.author.id) +"> Are you sure you want to buy " + str(conditions[1]) + " quantity of " + str(conditions[0]), color = 0x77FF87)
embedVar4.add_field(name="\u200b", value= "It will cost $" + str(price) + " you now have $" + str(endbal) + " remaining \nTransaction confirmed", inline=False)
await confirm_message.edit(embed = embedVar4) #message edit to confirmed
Thanks in advance,
Noel.

To make this message specific, simply add and reaction.message == message in check:
def check(reaction, user): #checks if user has reacted
return user == message.author and str(reaction.emoji) == '✅' and reaction.message == message
If you also want to have a cancel reaction, you should modify check to also allow cancel reactions:
def check(reaction, user): #checks if user has reacted
return user == message.author and str(reaction.emoji) in ['✅','Your cancel reaction here'] and reaction.message == confirm_message
and then check with which reaction the user reacted and do stuff depending on which reaction was used:
try:
reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check) #calls for function check defined prev
except asyncio.TimeoutError:
embedVar5 = discord.Embed(title="Money transfer", description="<#"+ str(message.author.id) +"> Are you sure you want to buy " + str(conditions[1]) + " quantity of " + str(conditions[0]), color = 0xFF0A26)
embedVar5.add_field(name="\u200b", value= "It would have cost $" + str(price) + " you would have had $" + str(endbal) + " remaining \nTransaction canceled", inline=False)
await confirm_message.edit(embed = embedVar5)
return
else:
if str(reaction.emoji) == '✅':
embedVar4 = discord.Embed(title="Money transfer", description="<#"+ str(message.author.id) +"> Are you sure you want to buy " + str(conditions[1]) + " quantity of " + str(conditions[0]), color = 0x77FF87)
embedVar4.add_field(name="\u200b", value= "It will cost $" + str(price) + " you now have $" + str(endbal) + " remaining \nTransaction confirmed", inline=False)
await confirm_message.edit(embed = embedVar4)
elif str(reaction.emoji) == 'Your cancel emoji here':
await confirm_message.edit(embed = embedVar5) #execute the same code you executed on TimeoutError
return
References:
Reaction.message

Related

My nextcord (python) is ignoring the if statements below the first if statement and can't figure out why

Sorry if this is a dumb question, however whenever I'm running my code it does not listen to the if statements within the if statement?
#bot.command()
#commands.has_role('Moderator')
async def activity(ctx):
days = datetime.datetime.now() - datetime.timedelta(days=7)
print(days)
for member in ctx.guild.members:
for role in member.roles:
if role.name == "Trusted Member":
if role.name == "Exempt":
print("<#" + str(member.id) + "> has a perm exemption")
elif role.name == "Temp Exempt":
print("<#" + str(member.id) + "> has a temp exemption, it has now been removed...")
else:
counter = 0
channel = bot.get_channel(1)
async for message in channel.history(limit=None, after=days):
if message.author == member:
counter += 1
print("<#" + str(member.id) + "> has sent " + str(counter))
The script will not check if they have an exempt role and instead just proceed to check how many messages they have sent.
Thanks in advance.
Working solution I found with help thanks to Rani
#bot.command()
#commands.has_role('Moderator')
async def activity(ctx):
days = datetime.datetime.now() - datetime.timedelta(days=7)
for member in ctx.guild.members:
role_names = []
for role in member.roles:
role_names.append(role.name)
if "Trusted Member" in role_names:
if "Exempt" in role_names:
print("<#" + str(member.id) + "> has a perm exemption")
elif "Temp Exempt" in role_names:
print("<#" + str(member.id) + "> has a temp exemption, it has now been removed...")
else:
counter = 0
channel = bot.get_channel(1)
async for message in channel.history(limit=None, after=days):
if message.author == member:
counter += 1
print("<#" + str(member.id) + "> has sent " + str(counter))```

How do you reference a string on a different line in python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm doing some code atm which currently does a request and then goes to another channel, and edits a schedule that adds what the person requested, I am currently working to make it so you can set it up in a discord server instead of my current system (referencing specific discord channels for testing) atm the Mondaymsg string etc. aren't being found by the Monday area on my code, and I don't know what to change to get it to reference, I am an on-the-go learner coder so my code may look bad but I hope I can get some help so I can improve.
#bot.command(name='raid', pass_context=True)
async def raid(ctx, arg, arg1 = None, arg2 = None, arg3 = None,*, role_name = None):
if arg == 'setup' :
setupchannel = ctx.channel
ctx.channel.purge(amount=1)
await setupchannel.send("**=====** __**RAID SCHEDULE**__ **=====**")
Mondaymsg = await setupchannel.send("__**Monday**__")
Tuesdaymsg = await setupchannel.send("__**Tuesday**__")
Wednesdaymsg = await setupchannel.send("__**Wednesday**__")
Thursdaymsg = await setupchannel.send("__**Thursday**__")
Fridaymsg = await setupchannel.send("__**Friday**__")
Saturdaymsg = await setupchannel.send("__**Saturday**__")
Sundaymsg = await setupchannel.send("__**Sunday**__")
elif arg == 'add':
if arg1 == 'Monday':
Userping = ctx.author.mention
Message = Mondaymsg()
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
messageContent = Mondaymsg.message.content
if arg3 in str(Mondaymsg.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await Mondaymsg.edit(content=messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Tuesday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879568853045235773)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Wednesday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879569158092783667)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Thursday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879569232336125972)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Friday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879569295313600573)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Saturday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879569379363258438)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Sunday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879569473688973403)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
else:
await ctx.channel.send("I'm sorry, your day input was invalid, please put one of the following days:\n\n"
"*Monday*\n"
"*Tuesday*\n"
"*Wednesday*\n"
"*Thursday*\n"
"*Friday*\n"
"*Saturday*\n"
"*Sunday*"
)
elif arg == 'clear':
channel = bot.get_channel(879538507905921125)
mondaymessage = await channel.fetch_message(879568766365736972)
tuesdaymessage = await channel.fetch_message(879568853045235773)
wednesdaymessage = await channel.fetch_message(879569158092783667)
thursdaymessage = await channel.fetch_message(879569232336125972)
fridaymessage = await channel.fetch_message(879569295313600573)
saturdaymessage = await channel.fetch_message(879569379363258438)
sundaymessage = await channel.fetch_message(879569473688973403)
await mondaymessage.edit(content='**__Monday__**')
await tuesdaymessage.edit(content='**__Tuesday__**')
await wednesdaymessage.edit(content='**__Wednesday__**')
await thursdaymessage.edit(content='**__Thursday__**')
await fridaymessage.edit(content='**__Friday__**')
await saturdaymessage.edit(content='**__Saturday__**')
await sundaymessage.edit(content='**__Sunday__**')
It looks like you're asking why variables defined in the first IF body aren't accessible in other IF bodies:
def func():
if some_condition:
var1 = 'blah'
var2 = 'asdf'
elseif other_condition:
# trying to access var1 or var2 here will result in a syntax error
This is because the two IF statement bodies are different scopes.
One simple option is to first define them with some default value (e.g. None) outside the function, creating global variables (in the global scope):
var1 = None
var2 = None
def func():
if some_condition:
var1 = 'blah'
var2 = 'asdf'
elif other_condition:
# now var1 and var2 are accessible here,
# but you must check or make sure they've been set
# to the values you want, meaning
# you must ensure func() has been called earlier
# with `some_condition` as true
But often defining global variables is not good practice. One alternative is to have your function accept a state variable that it modifies:
class State(object):
def __init__(self):
self.var1 = None
self.var2 = None
def func(state):
if some_condition:
state.var1 = 'blah'
state.var2 = 'asdf'
elif other_condition:
# can use state.var1 and state.var2
if __name__ == '__main__':
state = State()
# can now call func(state) to read or write state.var1 and state.var2

discord bot python invalid syntax

i am working on a python bot but i've come across a syntax error with ELIF and IF statements, and ive tried fiddling around changing the elif around, and adding an else instead n such, but i can't get it to work, so that's why i come on here to see if anyone has a solution for my problem, thanks.
My code:
#bot.command()
async def linkdiscord(ctx, token):
author = ctx.message.author
author2 = str(ctx.message.author)
discordid = ctx.message.author.id
response = json.loads(requests.get(forumurl + f"/api?action=linkdiscord&key=SECRET&token={token}&discordid={discordid}").text)
if response["status"] == 200:
embed=discord.Embed(title="Linker System", color=0xcd65f0)
embed.add_field(name="Linked Discord", value="Yes", inline=True)
embed.set_footer(text="Successfully linked " + author2 + " to forum account: " + response["username"])
elif response["status"] == 400:
embed=discord.Embed(title="Linker System", color=0xff0000)
embed.add_field(name="Unexpected error", value="True", inline=True)
embed.add_field(name="Message", value= response["message"], inline=True)
embed.set_footer(text="Error")
await ctx.send(embed=embed)
await ctx.message.delete()
elif response["status"] == 420:
server_id = 741131311467516961
server = client.get_guild(server_id)
member = server.get_member(ctx.message.author.id)
await ctx.guild.ban(member, reason=response["reason"])
Regards.
Python scope is determined by whitespace; The await calls should be in the elif scope.
Also, it's considered best practice to use 4 spaces for each indent. See PEP8 for more details.
#bot.command()
async def linkdiscord(ctx, token):
author = ctx.message.author
author2 = str(ctx.message.author)
discordid = ctx.message.author.id
response = json.loads(requests.get(forumurl + f"/api?action=linkdiscord&key=SECRET&token={token}&discordid={discordid}").text)
if response["status"] == 200:
embed=discord.Embed(title="Linker System", color=0xcd65f0)
embed.add_field(name="Linked Discord", value="Yes", inline=True)
embed.set_footer(text="Successfully linked " + author2 + " to forum account: " + response["username"])
elif response["status"] == 400:
embed=discord.Embed(title="Linker System", color=0xff0000)
embed.add_field(name="Unexpected error", value="True", inline=True)
embed.add_field(name="Message", value= response["message"], inline=True)
embed.set_footer(text="Error")
await ctx.send(embed=embed) # Now I'm in the correct scope!
await ctx.message.delete() # Me too!
elif response["status"] == 420:
server_id = 741131311467516961
server = client.get_guild(server_id)
member = server.get_member(ctx.message.author.id)
await ctx.guild.ban(member, reason=response["reason"])

Why is my on_message event printing logs twice?

Here is the logging bit of my on_message command, whenever I send "ping" it checks to make sure it's in its list of commands then logs it, but its logging it twice and sending once (It should only send once)...
async def on_message(message):
# Check if the message was from server
if message.content != "":
# Test if User/ Bot
if message.author == bot.user:
return
# Report Comamnd used
else:
splitCommand = message.content.split(" ")
join = " "
join = join.join(splitCommand)
time = "[UTC " + str(message.created_at) + "]"
singleCommand = "\nCommand: \'" + splitCommand[0] + "\'"
multiCommand = "\nCommand: \'" + join + "\'"
user = "\nFrom User: \'<#" + str(message.author.id) + "> | (" + str(message.author) + ")\'"
# Single word commands
if splitCommand[0].lower() in commandList:
print(time + singleCommand + user)
# Multi-word commands
if any(x.isalpha() or x.isspace() for x in join):
if join.lower() in commandList:
print(time + multiCommand + user)
elif regex.search(join) != None and join.lower() in commandList:
print(time + multiCommand + user)
# Deletes Commands
if message.content[0] == prefix:
userMessage = message
await userMessage.delete()
print("Deleted Command")
else:
pass
An example output would be:
[UTC 2020-11-24 08:21:42.587000]
Command: 'ping'
From User: '<#379355817700491264> | (24Kings#0001)'
[UTC 2020-11-24 08:21:42.587000]
Command: 'ping'
From User: '<#379355817700491264> | (24Kings#0001)'
Sent: 'pong'
But it should only be logging it once?
Any ideas as to why it is logging twice and a fix would be very much appreciated! :D
First of all it is better to use discord.ext.commands, After that you have three options.
on_command_error(ctx,error) To check for error and tell the user (permissions, wrong argument, etc..)
on_command(ctx)
on_command_completion(ctx)
#bot.event
async def on_command_completion(ctx):
print(f'{ctx.command} has been used by {ctx.author.display_name}')
For commands here is a ref

How to make a function that is done every 24 hours without stopping the whole program with time.sleep() for that time?

I have a Discord bot that stores a deadline for a user in a message channel. After the deadline ends, I want the bot to notify the moderators so they can deal with it.
Everything for the bot besides that is already done. My idea for this issue is to just have a function that checks the channel with deadlines every 24 hours and finds the same date on it as the current date and takes out the userid (which is also stored in said message).
I'm open to other solutions for this problem.
I've read up and Googled a bunch. It, at least, seems like to me that time.sleep() and schedule.every will stop my whole program for that time, but maybe I'm wrong about the schedule thing, because I tried to implement it into my code, but I got no idea how to make it work. I have only a week of Python experience here, bear with me.
Here is pretty much my whole code if it helps (without the bot token part, of course)
import datetime
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
import random
from discord import Game
from discord.utils import get
from datetime import datetime, timedelta
Client = discord.client
client = commands.Bot(command_prefix = '%')
Clientdiscord = discord.Client()
#client.event
async def on_ready():
await client.change_presence(game=Game(name='with nuclear waste'))
print('Ready, bitch')
#client.event
async def on_reaction_add(reaction, user):
if ' has sent an application to become a full fledged FRICK' in reaction.message.content:
Name = reaction.message.content.split('#')
usid = reaction.message.content.split('=')
usid1 = usid[1].split(' ')
user =reaction.message.server.get_member(usid1[0])
msg = reaction.message.content.split('?')
eventcode = str (msg[1])
cont = str(msg[0])
kakapoopoo = '#' + usid1[0]
#await client.send_message(user, 'test')
if reaction.emoji == get(client.get_all_emojis(), name='FeelsBadMan'):
await client.send_message(client.get_channel('560678137630031872'), Name[0] + ' has attented 1 event.')
await client.edit_message(reaction.message, cont + '?01')
if reaction.emoji == get(client.get_all_emojis(), name='veetsmug'):
await client.send_message(client.get_channel('560678137630031872'), Name[0] + ' has attented 2 events.')
await client.edit_message(reaction.message, cont + '?10')
if reaction.emoji == get(client.get_all_emojis(), name='POGGERS'):
await client.edit_message(reaction.message, cont + '?11')
await client.send_message(client.get_channel('560678137630031872'), Name[0] + ' has attented 3 events.')
if reaction.emoji == get(client.get_all_emojis(), name='HYPERS'):
role1 = discord.utils.get(reaction.message.server.roles, name='Pending Frick')
await client.remove_roles(user, role1)
await client.send_message(client.get_channel('560678137630031872'), user.mention + ' has attented 4 events and is now a ***FRICK***.\n#here')
role2 = discord.utils.get(reaction.message.server.roles, id='561087733834186754')
await client.add_roles(user, role2)
await client.send_message(user, 'You are now a full fledged ***FRICK***')
await client.delete_message(reaction.message)
elif 'To approve screenshot react with :HYPERS: to dissaprove react with :FeelsBadMan:' in reaction.message.content:
cunt = reaction.message.content.split('#')
name = cunt[0]
idududu = reaction.message.content.split('?')
peepee = idududu[1]
#await client.send_message(client.get_channel('560678137630031872'), 'test' + peepee)
idud = peepee.split('\nThe events the user has attented before are:')
usid = idud[0]
#await client.send_message(client.get_channel('560678137630031872'), 'test' + usid)
#await client.send_message(client.get_channel('560678137630031872'), 'test' +str(usid))
user=await client.get_user_info(usid)
event = reaction.message.content.split('has attented a ')
eventu = event[1]
evento = eventu.split('Screenshot:')
if reaction.emoji == get(client.get_all_emojis(), name='HYPERS'):
await client.send_message(user, 'Your screenshot has been approved')
await client.delete_message(reaction.message)
async for message in client.logs_from(discord.Object(id='561667365927124992'), limit = 100):
#await client.send_message(user, 'test')
if name in message.content:
if ' eventcode?00' in message.content:
await client.send_message(user, 'You have attented 1 event')
emoji = get(client.get_all_emojis(), name='FeelsBadMan')
await client.add_reaction(message, emoji)
await client.send_message(discord.Object(id='562607755358371840'), str(usid) + ' ' + str(evento[0]))
elif ' eventcode?01' in message.content:
await client.send_message(user, 'You have attented 2 events')
emoji = get(client.get_all_emojis(), name='veetsmug')
await client.add_reaction(message, emoji)
async for message in client.logs_from(discord.Object(id='562607755358371840'), limit = 100):
if usid in message.content:
cont = message.content
await client.edit_message(message, cont + ', ' + str(evento[0]))
elif ' eventcode?10' in message.content:
await client.send_message(user, 'You have attented 3 events')
emoji = get(client.get_all_emojis(), name='POGGERS')
await client.add_reaction(message, emoji)
async for message in client.logs_from(discord.Object(id='562607755358371840'), limit = 100):
if usid in message.content:
cont = message.content
await client.edit_message(message, cont + ', ' + str(evento[0]))
elif ' eventcode?11' in message.content:
emoji = get(client.get_all_emojis(), name='HYPERS')
await client.add_reaction(message, emoji)
async for message in client.logs_from(discord.Object(id='562607755358371840'), limit = 100):
if usid in message.content:
await client.delete_message(message)
elif reaction.emoji == get(client.get_all_emojis(), name='FeelsBadMan'):
await client.send_message(user, 'Your screenshot has not been approved')
await client.delete_message(reaction.message)
#client.event
async def on_message(message):
if message.content == '%start':
if "561047714230435871" in [role.id for role in message.author.roles]:
deadline = datetime.now() + timedelta(days=21)
author = message.author
mes = str(author) + ' has sent an application to become a full fledged FRICK id ='+ str(message.author.id) + ' Deadline+' +str(deadline.strftime("%Y-%m-%d")) + ' eventcode?00'
emoji = get(client.get_all_emojis(), name='HYPERS')
await client.add_reaction(message, emoji)
role = get(message.server.roles, id='561055432748302336')
await client.add_roles(message.author, role)
await client.send_message(client.get_channel('561667365927124992'), mes)
await client.send_message(message.author, '***You have entered the Frickling program!**\n\nTo become a full fledged Frick you must attend 4 guild/alliance events. Please provide screensots to the bot proving that you have attented them by using %attended command followed by a screenshot **LINK** and the name of the activity.\n\n Example: %attented https://cdn.discordapp.com/attachments/530909412320083969/558085258164305921/guild_event_2.jpg fame farm')
role = get(message.server.roles, name='Frickling')
await client.remove_roles(message.author, role)
elif "561055432748302336" in [role.id for role in message.author.roles]:
await client.send_message(message.channel,'Seems like you already started the application process for becoming a full fledged Frick')
else:
await client.send_message(message.channel,'Seems like you do not have the permisssions to use me.\n\nIt might be because your application for Frickling has not yet been approved or you are already a full fledged Frick')
elif message.content == 'Tell that bot to get lost':
if message.author == message.server.get_member('336858563064496130'):
await client.send_message(message.channel,'Get lost, stupid bot')
elif message.content == 'Tell Meatcup to get lost':
if message.author == message.server.get_member('336858563064496130'):
user = discord.utils.get(reaction.message.server.members, id ='331864154803666945')
await client.send_message(user, 'Get lost, Meatcup')
elif message.content == '%cunt':
await client.send_message(message.channel,'Yes, my master?')
emoji = get(client.get_all_emojis(), name='HYPERS')
await client.add_reaction(message, emoji)
elif message.content == '%testfrick':
if "561087733834186754" in [role.id for role in message.author.roles]:
await client.send_message(message.channel,'You are a frick')
else:
await client.send_message(message.channel,'Error')
elif message.content == '%testpend':
if "561055432748302336" in [role.id for role in message.author.roles]:
await client.send_message(message.channel,'You are pending')
else:
await client.send_message(message.channel,'Error')
elif '%attended' in message.content and message.author.id != '560634369094582302':
author = message.author
authid = message.author.id
cunt = 0
msg = message.content.split(' ',2)
if len(msg) > 2:
emoji = get(client.get_all_emojis(), name='HYPERS')
await client.add_reaction(message, emoji)
for i in client.servers:
for x in i.roles:
if x.id == '561055432748302336':
async for message in client.logs_from(discord.Object(id='562607755358371840'), limit = 100):
if authid in message.content:
eventu = message.content.split(' ',1)
cunt = 1
await client.send_message(discord.Object(id='560679934209687552'), str(author) + ' has attented a ' + msg[2] + '\nScreenshot:' + msg[1] + '\nTo approve screenshot react with :HYPERS: to dissaprove react with :FeelsBadMan:\nUserid?'+authid + '\nThe events the user has attented before are: ' + str(eventu[1]))
if cunt == 0:
await client.send_message(discord.Object(id='560679934209687552'), str(author) + ' has attented a ' + msg[2] + '\nScreenshot:' + msg[1] + '\nTo approve screenshot react with :HYPERS: to dissaprove react with :FeelsBadMan:\nUserid?'+ authid)
else:
await client.send_message(message.author,'Error. You did not provide the name of the event or you only provided the name of the event.')
For asynchronous python, when non-blocking sleeping is required, you can use the method asyncio.sleep(n), n being the number of seconds you want the method to sleep for. So a basic async method that sleeps once every 24 hours would look something like this:
async def daily_task():
print('This method will NOT block')
await asyncio.sleep(24*60*60)
EDIT: Thanks go to Benjin, who pointed out that I forgot to await the sleep.
Threads will let you work "simultaneously" on 2 things (or more...). When one thread will sleep, another thread can do "the rest"

Categories

Resources