Creating meme command with discord.py [closed] - discord.py

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
Can someone help me how to create meme command like dank memer. Below is the photo of the command i want to make.
enter image description here

This is the meme command I am using now. This is also similar to dank memer.
This is from the library of discord_compoenents. You can refer the docs for using the button
#commands.command(aliases=['me'])
#commands.guild_only()
#commands.cooldown(1, 3, commands.BucketType.user)
async def meme(self,ctx):
serverId = ctx.message.guild.id
def meme_opt():
choices=[1,2]
chosen=random.choice(choices)
if(chosen==1):
'''Post a meme'''
r = requests.get("https://memes.blademaker.tv/api?lang=en")
res = r.json()
title = res["title"]
ups = res["ups"]
# downs = res["downs"]
comments = res['score']
authors=res["author"]
memes = discord.Embed(title=f"{title}",colour=randint(0, 0xffffff))
memes.set_image(url=res["image"])
memes.set_footer(text=f"👍 : {ups} ✍️ : {authors} 💬 : {comments} ")
else:
###################
r=requests.get("https://meme-api.herokuapp.com/gimme")
res=r.json()
title=res["title"]
ups=res["ups"]
author=res["author"]
link=res["postLink"]
memes = discord.Embed(description=f"[{title}]({link})",colour=randint(0, 0xffffff))
memes.set_image(url=res["url"])
memes.set_footer(text=f"👍 : {ups} ✍️ : {author}")
return memes
components = [
[
Button(label='Next meme', style=ButtonStyle.green, custom_id='next'),
Button(label='End interaction', style=ButtonStyle.red, custom_id='exit')
]
]
message = await ctx.send(embed=meme_opt(), components=components)
id=message.id
while True:
try:
interaction = await self.bot.wait_for(
'button_click',
check=lambda inter: inter.message.id == message.id,
timeout=30
)
except asyncio.TimeoutError:
for row in components:
row.disable_components()
return await message.edit(components=components)
if(interaction.author.id==ctx.author.id):
if(interaction.custom_id=="next"):
await interaction.edit_origin(embed=meme_opt(),components=components)
elif(interaction.custom_id=="exit"):
for row in components:
row.disable_components()
message=await ctx.fetch_message(id)
return await interaction.edit_origin(embed=message.embeds[0],components=components)
else:
await interaction.send("Hey! This is not for you!")

Related

Getting input from reactions not working discord.py

I wanted to make a rock paper scissor game for my bot:
The bot creates an embed with instructions and reacts with a "rock", "paper", and "scissor" emoji, which the user has to click to input his/her choice.
But the problem is that the code doesn't go any further and shows an error.
Here is the code:
#client.command(aliases = ["rock_paper_scissors","rps"])
async def _rps(ctx): #rps is short for rock, paper, scissor
emojis = ['✊', '🖐️', '✌️']
embedVar = discord.Embed(title="CHOOSE YOUR WEAPON!",description = "Choose between rock, paper, or scissors, {}." . format(ctx.author.mention), color = 0xff9900)
embedVar.add_field(name=":fist: ROCK", value="React with :fist: emoji to choose rock.", inline = False)
embedVar.add_field(name=":hand_splayed: PAPER", value="React with :hand_splayed: emoji to choose paper.", inline = False)
embedVar.add_field(name=":v: SCISSORS", value="React with :v: emoji to choose scissors.", inline = False)
emb = await ctx.send(embed = embedVar)
for emoji in emojis:
await emb.add_reaction(emoji)
def chk(reaction):
return reaction.emb == emb and reaction.channel == ctx.channel
react = await client.wait_for('reaction_add', check=chk)
if react == '✊':
await ctx.send("You chose rock!")
elif react == '🖐️':
await ctx.send("You chose paper!")
elif react == '✌️':
await ctx.send("You chose scissors!")
I am getting this error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: chk() takes 1 positional argument but 2 were given
I tried many fixes but in vain.
Also, I want the bot to accept the input only from the user who had asked for the rock paper scissor game by the command in the first place (the author of the message, in other words), But I am not sure how to implement that, I tried, but it did not work.
How can I fix this?
reaction_add gives a tuple of a reaction and a user so in the chk function you need to have both the reaction and user. You should also use and user == ctx.author within the chk function to ensure the user is the same.
#client.command(aliases = ["rock_paper_scissors","rps"])
async def _rps(ctx): #rps is short for rock, paper, scissor
emojis = ['✊', '🖐️', '✌️']
embedVar = discord.Embed(title="CHOOSE YOUR WEAPON!",description = "Choose between rock, paper, or scissors, {}." . format(ctx.author.mention), color = 0xff9900)
embedVar.add_field(name=":fist: ROCK", value="React with :fist: emoji to choose rock.", inline = False)
embedVar.add_field(name=":hand_splayed: PAPER", value="React with :hand_splayed: emoji to choose paper.", inline = False)
embedVar.add_field(name=":v: SCISSORS", value="React with :v: emoji to choose scissors.", inline = False)
emb = await ctx.send(embed = embedVar)
for emoji in emojis:
await emb.add_reaction(emoji)
def chk(reaction, user):
return reaction.emb == emb and reaction.channel == ctx.channel and user == ctx.author
react, user = await client.wait_for('reaction_add', check=chk)
if react == '✊':
await ctx.send("You chose rock!")
elif react == '🖐️':
await ctx.send("You chose paper!")
elif react == '✌️':
await ctx.send("You chose scissors!")

Ruby Yaml - Create instance Variables Directly from a YML file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Hi I want to create A YML file and load them as instance variables instead. How can I do that.
yml_File.yml File ::
default:
browserversion: 43
dev:
browser_02: iexplore
qa_01:
browser_default: chrome
qa_02:
browser_default: safari
Check the below Code::
p yml_File = YAML.load_file(File.dirname(__FILE__).gsub('/', '\\') + '\\Profiles.yml')
yml_File.each_key {|key_Value|
va = yml_File[key_Value].to_s
var_name = "##{key_Value}" # the '#' is required
self.instance_variable_set(var_name, va)
p "Name of Instance variable '#{key_Value}' is :: " + var_name.to_s + ' - And Key value is : ' + eval("##{key_Value}")
}
p #dev
p #qa_01
p #qa_02
Note - Ruby 1.9+ atleast

Reformatting a hash with new keys (as symbols) based on date format [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 8 years ago.
Improve this question
I need to convert this:
[{"day"=>"2014-02-01", "users"=>1234},
{"day"=>"2014-02-02", "users"=>2234},
{"day"=>"2014-02-03", "users"=>3234},
{"day"=>"2014-02-04", "users"=>4234}]
into this:
[{:x=>1, y:=>1234},
{:x=>2, y:=>2234},
{:x=>3, y:=>3234},
{:x=>4, y:=>4234}]
a = [{"day"=>"2014-02-01", "users"=>1234}, {"day"=>"2014-02-02", "users"=>2234}, {"day"=>"2014-02-03", "users"=>3234}, {"day"=>"2014-02-04", "users"=>4234}]
a.map.with_index(1) { |h,i| { :x => i, :y => h['users'] } }
# => [{:x=>1, :y=>1234}, {:x=>2, :y=>2234}, {:x=>3, :y=>3234}, {:x=>4, :y=>4234}]

Is there a neater way to put these hashes/arrays? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I have a method from a long script that creates a hash from genetic sequences, however it is really messy and thus I was wondering whether there was a way to put it more elegantly.
Here is a sample of the script (i.e. it contains an example)...
def make_hash(motif)
main_hash = Hash.new
id = ">isotig00009_f2_3 ~: S.P. Cleavage Site: 22:23 - S.P. D-value: 0.532"
seq = "MLKCFSIIMGLILLLEIGGGCA~IYFYRAQIQAQFQKSLTDVTITDYRENADFQDLIDALQSGLSCCGVNSYEDWDNNIYFNCSGPANNPEALWCAFLLLYTGSSKRSSQHPVRLWSSFPRTTKYFPHKDLHHWLCGYVYNVD"
id_hash = Hash[[[:id_start, :id_end], id.split("~").map(&:strip)].transpose]
seq_hash = Hash[[[:signalp, :seq_end], seq.split("~").map(&:strip)].transpose]
signalp = seq_hash[:signalp]
new_seq_end = seq_hash[:seq_end].gsub(/#{motif}/, '<span class="motif">\0</span>')
new_seq_hash = Hash[:signalp => signalp, :new_seq_end => new_seq_end ]
main_hash[id_hash] = [new_seq_hash]
return main_hash
end
motif = "VT|QAQ|F.D"
main_hash = make_hash(motif)
main_hash.each do |id_hash, seq_hash|
puts id_hash[:id_start]
puts id_hash[:id_end]
puts seq_hash[0][:signalp]
puts seq_hash[0][:new_seq_end]
end
So Is there a more elegant way to write the make_hash method...
Many Thanks
I haven't tested this, but I think this simplification will work:
def make_hash(motif)
id = ">isotig00009_f2_3 ~: S.P. Cleavage Site: 22:23 - S.P. D-value: 0.532"
seq = "MLKCFSIIMGLILLLEIGGGCA~IYFYRAQIQAQFQKSLTDVTITDYRENADFQDLIDALQSGLSCCGVNSYEDWDNNIYFNCSGPANNPEALWCAFLLLYTGSSKRSSQHPVRLWSSFPRTTKYFPHKDLHHWLCGYVYNVD"
id_hash = Hash[[[:id_start, :id_end], id.split("~").map(&:strip)].transpose]
f, s = seq.split("~").map(&:strip)
s.gsub!(/#{motif}/, '<span class="motif">\0</span>')
new_seq_hash = Hash[Hash[:signalp, f], Hash[:new_seq_end, s]]
Hash[id_hash, new_seq_hash]
end
If (as it appears) id and seq both have constant values, you might consider breaking them apart manually, rather than with id.split("~").map(&:strip); i.e.,
id1 = ">isotig00009_f2_3
id2 = ": S.P. Cleavage Site: 22:23 - S.P. D-value: 0.532"
seq1 = "MLKCFSIIMGLILLLEIGGGCA"
seq2 = "IYFYRAQIQAQFQKSLTDVTITDYRENADFQDLIDALQSGLSCCGVNSYEDWDNNIYFNCSGPANNPEALWCAFLLLYTGSSKRSSQHPVRLWSSFPRTTKYFPHKDLHHWLCGYVYNVD"
If there were a need to make seq2 more readable, we could use the "line continuation" character, \ (which even works within strings) like this:
seq2 = "IYFYRAQIQAQFQKSLTDVTITDYRENADFQDLIDALQSGLSCCGVNSYEDWDNNIYFNC"\
"SGPANNPEALWCAFLLLYTGSSKRSSQHPVRLWSSFPRTTKYFPHKDLHHWLCGYVYNVD"
or this:
seq2 = "IYFYRAQIQAQFQKSLTDVTITDYRENADFQDLIDALQSGLSCCGVNSYEDWDNNIYFNC\
SGPANNPEALWCAFLLLYTGSSKRSSQHPVRLWSSFPRTTKYFPHKDLHHWLCGYVYNVD"
If you preferred, you could make 'id' and 'seq' constants ('ID' and 'SEQ', say) and move them outside the method definition. Not surprisingly, line continuation also works for constant strings.

i need solution for imread [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i want to load my image call caltrain, there is 30 img.
i used code
for i = 0:30
imgINumber = i;
imgPNumber = i+2;
if imgINumber < 10
imgIFile = sprintf('C:\sequence01_caltrain_gray\caltrain/gray/%s00%d.ras',imageName, imageName, imgINumber);
elseif imgINumber < 100
imgIFile = sprintf('C:\sequence01_caltrain_gray\caltrain/gray/%s0%d.ras',imageName, imageName, imgINumber);
end
if imgPNumber < 10
imgPFile = sprintf('C:\sequence01_caltrain_gray\caltrain\gray/%s00%d.ras',imageName, imageName, imgPNumber);
elseif imgPNumber < 100
imgPFile = sprintf('C:\sequence01_caltrain_gray\caltrain\gray/%s0%d.ras',imageName, imageName, imgPNumber);
end
imgI = double(imread(imgIFile));
imgP = double(imread(imgPFile));
imgI = imgI(:,1:352);
imgP = imgP(:,1:352);
but error:
Error using ==> imread
Can't open file "C:" for reading;
you may not have read permission.
i need solution for this
thanks
Either double your backslashes or replace all the backslashes with slashes in your sprintf calls.

Resources