trying to list the most “voted on” messages with a specific reaction emoji on them
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Trying to do a thing where you enter a command and get a list of the top 5 messages with a reaction emoji called :goldmedal: . when entered into the bot, everything is fine, but when executing the command it starts a infinite loop of responses to every message it can find. and doesn't show the "goldmedal" value, but rather all the reactions on that specific message. https://cdn.discordapp.com/attachments/511938736594878478/512733361819746314/unknown.png
import discord
from discord import Game
from discord.ext.commands import Bot
from discord import Channel
from discord.utils import get
from discord.ext import commands
bot = Bot(command_prefix='!')
def num_reactions(message):
return sum(react_count for react in message.reactions)
@bot.command(pass_context=True)
async def most_reacted(ctx, channel: Channel):
most_reactions = most_reactions_message = None
goldmedal_emoji = get(ctx.message.server.emojis, name="goldmedal_emoji")
async for message in bot.logs_from(channel):
num_reactions_message = ([goldmedal_emoji])
num_reactions_message = num_reactions(message)
if not most_reactions or num_reactions_message > most_reactions:
most_reactions = num_reactions_message
most_reactions_message = message
await bot.say(f"{most_reactions_message.content} has the most Gold Medals with {most_reactions}")
python discord.py
add a comment |
Trying to do a thing where you enter a command and get a list of the top 5 messages with a reaction emoji called :goldmedal: . when entered into the bot, everything is fine, but when executing the command it starts a infinite loop of responses to every message it can find. and doesn't show the "goldmedal" value, but rather all the reactions on that specific message. https://cdn.discordapp.com/attachments/511938736594878478/512733361819746314/unknown.png
import discord
from discord import Game
from discord.ext.commands import Bot
from discord import Channel
from discord.utils import get
from discord.ext import commands
bot = Bot(command_prefix='!')
def num_reactions(message):
return sum(react_count for react in message.reactions)
@bot.command(pass_context=True)
async def most_reacted(ctx, channel: Channel):
most_reactions = most_reactions_message = None
goldmedal_emoji = get(ctx.message.server.emojis, name="goldmedal_emoji")
async for message in bot.logs_from(channel):
num_reactions_message = ([goldmedal_emoji])
num_reactions_message = num_reactions(message)
if not most_reactions or num_reactions_message > most_reactions:
most_reactions = num_reactions_message
most_reactions_message = message
await bot.say(f"{most_reactions_message.content} has the most Gold Medals with {most_reactions}")
python discord.py
2
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. "Doesn't work out much" isn't a problem specification. Your posted example needs some support code.
– Prune
Nov 15 '18 at 20:51
add a comment |
Trying to do a thing where you enter a command and get a list of the top 5 messages with a reaction emoji called :goldmedal: . when entered into the bot, everything is fine, but when executing the command it starts a infinite loop of responses to every message it can find. and doesn't show the "goldmedal" value, but rather all the reactions on that specific message. https://cdn.discordapp.com/attachments/511938736594878478/512733361819746314/unknown.png
import discord
from discord import Game
from discord.ext.commands import Bot
from discord import Channel
from discord.utils import get
from discord.ext import commands
bot = Bot(command_prefix='!')
def num_reactions(message):
return sum(react_count for react in message.reactions)
@bot.command(pass_context=True)
async def most_reacted(ctx, channel: Channel):
most_reactions = most_reactions_message = None
goldmedal_emoji = get(ctx.message.server.emojis, name="goldmedal_emoji")
async for message in bot.logs_from(channel):
num_reactions_message = ([goldmedal_emoji])
num_reactions_message = num_reactions(message)
if not most_reactions or num_reactions_message > most_reactions:
most_reactions = num_reactions_message
most_reactions_message = message
await bot.say(f"{most_reactions_message.content} has the most Gold Medals with {most_reactions}")
python discord.py
Trying to do a thing where you enter a command and get a list of the top 5 messages with a reaction emoji called :goldmedal: . when entered into the bot, everything is fine, but when executing the command it starts a infinite loop of responses to every message it can find. and doesn't show the "goldmedal" value, but rather all the reactions on that specific message. https://cdn.discordapp.com/attachments/511938736594878478/512733361819746314/unknown.png
import discord
from discord import Game
from discord.ext.commands import Bot
from discord import Channel
from discord.utils import get
from discord.ext import commands
bot = Bot(command_prefix='!')
def num_reactions(message):
return sum(react_count for react in message.reactions)
@bot.command(pass_context=True)
async def most_reacted(ctx, channel: Channel):
most_reactions = most_reactions_message = None
goldmedal_emoji = get(ctx.message.server.emojis, name="goldmedal_emoji")
async for message in bot.logs_from(channel):
num_reactions_message = ([goldmedal_emoji])
num_reactions_message = num_reactions(message)
if not most_reactions or num_reactions_message > most_reactions:
most_reactions = num_reactions_message
most_reactions_message = message
await bot.say(f"{most_reactions_message.content} has the most Gold Medals with {most_reactions}")
python discord.py
python discord.py
edited Nov 15 '18 at 20:59
Jesse miller Jim_Lock
asked Nov 15 '18 at 20:49
Jesse miller Jim_LockJesse miller Jim_Lock
11
11
2
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. "Doesn't work out much" isn't a problem specification. Your posted example needs some support code.
– Prune
Nov 15 '18 at 20:51
add a comment |
2
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. "Doesn't work out much" isn't a problem specification. Your posted example needs some support code.
– Prune
Nov 15 '18 at 20:51
2
2
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. "Doesn't work out much" isn't a problem specification. Your posted example needs some support code.
– Prune
Nov 15 '18 at 20:51
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. "Doesn't work out much" isn't a problem specification. Your posted example needs some support code.
– Prune
Nov 15 '18 at 20:51
add a comment |
1 Answer
1
active
oldest
votes
Your function here:
def num_reactions(message):
return sum(react_count for react in message.reactions)
only fetches the number of different reactions to a message instead of the count of reactions with the goldmedal emoji. You would probably want something like this instead:
def num_reactions(message):
for react in message.reactions:
if react.emoji.name === "goldmedal_emoji":
return react.count
There are also many long term issues with your approach being:
- It only obtains the last 100 messages from the log as the default limit of logs_from() is 100 (unless this is exactly what you want)
- The bot has to search the channel every single time the command is ran which will be SLOW
May I suggest a different approach that stores the highest 5 in memory (hopefully not RAM but a database, or other persistent storages such as text files, in case your bot ever crashes), replacing them instead when a new message has a higher count of "goldmedal_emoji" reactions.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327692%2ftrying-to-list-the-most-voted-on-messages-with-a-specific-reaction-emoji-on-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your function here:
def num_reactions(message):
return sum(react_count for react in message.reactions)
only fetches the number of different reactions to a message instead of the count of reactions with the goldmedal emoji. You would probably want something like this instead:
def num_reactions(message):
for react in message.reactions:
if react.emoji.name === "goldmedal_emoji":
return react.count
There are also many long term issues with your approach being:
- It only obtains the last 100 messages from the log as the default limit of logs_from() is 100 (unless this is exactly what you want)
- The bot has to search the channel every single time the command is ran which will be SLOW
May I suggest a different approach that stores the highest 5 in memory (hopefully not RAM but a database, or other persistent storages such as text files, in case your bot ever crashes), replacing them instead when a new message has a higher count of "goldmedal_emoji" reactions.
add a comment |
Your function here:
def num_reactions(message):
return sum(react_count for react in message.reactions)
only fetches the number of different reactions to a message instead of the count of reactions with the goldmedal emoji. You would probably want something like this instead:
def num_reactions(message):
for react in message.reactions:
if react.emoji.name === "goldmedal_emoji":
return react.count
There are also many long term issues with your approach being:
- It only obtains the last 100 messages from the log as the default limit of logs_from() is 100 (unless this is exactly what you want)
- The bot has to search the channel every single time the command is ran which will be SLOW
May I suggest a different approach that stores the highest 5 in memory (hopefully not RAM but a database, or other persistent storages such as text files, in case your bot ever crashes), replacing them instead when a new message has a higher count of "goldmedal_emoji" reactions.
add a comment |
Your function here:
def num_reactions(message):
return sum(react_count for react in message.reactions)
only fetches the number of different reactions to a message instead of the count of reactions with the goldmedal emoji. You would probably want something like this instead:
def num_reactions(message):
for react in message.reactions:
if react.emoji.name === "goldmedal_emoji":
return react.count
There are also many long term issues with your approach being:
- It only obtains the last 100 messages from the log as the default limit of logs_from() is 100 (unless this is exactly what you want)
- The bot has to search the channel every single time the command is ran which will be SLOW
May I suggest a different approach that stores the highest 5 in memory (hopefully not RAM but a database, or other persistent storages such as text files, in case your bot ever crashes), replacing them instead when a new message has a higher count of "goldmedal_emoji" reactions.
Your function here:
def num_reactions(message):
return sum(react_count for react in message.reactions)
only fetches the number of different reactions to a message instead of the count of reactions with the goldmedal emoji. You would probably want something like this instead:
def num_reactions(message):
for react in message.reactions:
if react.emoji.name === "goldmedal_emoji":
return react.count
There are also many long term issues with your approach being:
- It only obtains the last 100 messages from the log as the default limit of logs_from() is 100 (unless this is exactly what you want)
- The bot has to search the channel every single time the command is ran which will be SLOW
May I suggest a different approach that stores the highest 5 in memory (hopefully not RAM but a database, or other persistent storages such as text files, in case your bot ever crashes), replacing them instead when a new message has a higher count of "goldmedal_emoji" reactions.
answered Nov 17 '18 at 6:34
OrphamielOrphamiel
8041121
8041121
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327692%2ftrying-to-list-the-most-voted-on-messages-with-a-specific-reaction-emoji-on-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. Minimal, complete, verifiable example applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. "Doesn't work out much" isn't a problem specification. Your posted example needs some support code.
– Prune
Nov 15 '18 at 20:51