Hey everyone! I’m working on a Discord bot using Python and I’m stuck on a feature. I want the bot to mention a user multiple times in separate messages. The number of mentions should be random, anywhere from 0 to 1000.
I’ve tried something like this:
@bot.event
async def on_message(message):
if message.content.startswith('!mention'):
times = random.randint(0, 1000)
await message.channel.send(f'Starting mentions! Total: {times}')
for _ in range(times):
await message.channel.send(message.author.mention)
But it’s not working quite right. The bot seems to get rate-limited or something. Any ideas on how to make this work smoothly? Maybe there’s a better way to approach this? I’m pretty new to Discord bot development, so any help would be awesome. Thanks!
As someone who’s been developing Discord bots for a while, I can tell you that spamming mentions like that is generally frowned upon and can get your bot in trouble. Instead, I’d suggest a more user-friendly approach.
You could implement a system where the bot sends a single message with multiple mentions, but spaced out with newlines or in a formatted embed. This way, you avoid rate limits and don’t annoy users with constant pings.
Here’s a rough idea:
@bot.command()
async def mention(ctx, user: discord.Member, times: int):
if times > 50: # Set a reasonable limit
await ctx.send('Sorry, that\'s too many mentions!')
return
mentions = '\n'.join([user.mention for _ in range(times)])
await ctx.send(f'Mentions for {user.name}:\n{mentions}')
This approach is more respectful to users and Discord’s systems. Remember, a good bot enhances the Discord experience, not disrupts it!
I’ve dealt with similar issues when developing Discord bots. Spamming mentions like that can quickly hit rate limits and potentially get your bot flagged. Instead, I’d recommend consolidating the mentions into fewer messages.
Here’s an approach that might work better:
@bot.command()
async def mention(ctx, user: discord.Member):
times = random.randint(0, 1000)
mentions = [user.mention] * times
chunks = [mentions[i:i+20] for i in range(0, len(mentions), 20)]
await ctx.send(f'Mentioning {user.name} {times} times:')
for chunk in chunks:
await ctx.send(' '.join(chunk))
await asyncio.sleep(1) # Add a delay to avoid rate limits
This groups mentions into chunks of 20, sends them as separate messages, and adds a small delay between messages. It’s more efficient and less likely to trigger rate limits or annoy users. Just be mindful of server rules regarding spam!
yo dude, spamming mentions like that’s gonna get ur bot in hot water real quick. discord ain’t gonna like that. maybe try bundling the mentions in one message? something like: