Discord Bot stops working after a command - discord

I am making a discord bot with pycord, but when I added a command to get the latest post of a twitter account the bot stops working.
The bot sends the 5 latest posts and then adds them to a list to not send the same post twice.
But after posted.append(twitter.id) the bot stops reacting to other commands.
I can't figure out what is happening.
async def get_latest_post(ctx):
tweets = await twitter.get_users_tweets(id="1299389003477573632", max_results=5)
posted = []
while True:
for tweet in tweets.data:
if tweet.id in posted:
pass
else:
await ctx.respond(
f"https://twitter.com/twitter/statuses/{tweet.id}"
)
posted.append(tweet.id)

Related

Discord.py wait_for command when user adds reaction

So I need some help!
So far I have the code do the following... Someone inputs the !stage command and then their stage(int)... It sends a message in another where the FTO will react to the message. When reacted the FTO will get a DM with info!
So my question is how do I use wait_for for the user who originally sent the command to be contacted by the bot when the FTO clicks the reactions. Like I need the bot to send that original command user a DM with who clicked the reaction.
#client.command()
async def stage(ctx, *, stage):
ftochannel = client.get_channel(1043289756794093639)
logchannel = client.get_channel(1037550844935147622)
embed=discord.Embed(title=f"{ctx.author.mention} has requested ride along for stage **{stage}**",description=f"If you want to assist this member with their requested stage react below!", color=0x660066)
log=discord.Embed(title=f"Discord Log // User Requested Ride Along in BCSO Discord",description=f'Ran By: {ctx.author.mention}\nActual Command Finish: {ctx.author.mention} has just requested the following stage: {stage}! ',color=0x660066)
emoji = "\N{Large Yellow Circle}"
msg = await ftochannel.send(embed=embed)
await msg.add_reaction(emoji)
await ctx.send("When an FTO member answers me You will get a message from me with more information! Please be patient!")
await logchannel.send(embed=log)
#client.event
async def on_raw_reaction_add(payload):
if str(payload.emoji) == "\N{Large Yellow Circle}":
member = payload.member
sendEmbedToUser = discord.Embed(title=f'Hello', description=f'You have accepted THIS PERSONS Stage RIDE ALONG!\nPlease Arrive in <#1038926472259313732> within **10 Minutes**!\n\nHere is some helpful documentation for your ride along:\n[LINK SHORTNER 1]\n[LINK SHORTNER 1]\n[LINK SHORTNER 1]\n[LINK SHORTNER 1]')
await member.send(embed=sendEmbedToUser)
[]
With some help from friends I no know I need to used wait_for somewhere in the stage command but I have no clue how to do it!

Can I catch discord Dyno bot message and auto reply to it?

As title, my scenario is:
Periodically checking if new messages were sent by Dyno bot to specific channel, and reply to it automatically.
Is it possible?
[update1]
Here are some cases:
select the right option based one the message sent by bot
click the right button based one the message sent by bot
[update2]
add some figures. something like these:
Any suggestion is appreciated.
Using discord.py, you can check if a message is written by a bot and reply to it with:
#client.event
async def on_message(self, message): #call the on_message() function
if (message.author.bot): #check if the author is a bot
await message.reply('Hello, bot!') #reply to the bot

Discord Bot Take User's Text and Post it

I am looking for a discord bot made in .py that does those 3 things:
post to a specific channel
whatever user writes then bot deletes it and post it
information of who wrote what in another specific channel. example:
{user} wrote Hi my name is Nick
Thanks in advance! I have not tried something yet, because I am not that experienced. Thanks a lot.
Try this
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='prefix')
#bot.command()
async def say(ctx, channel: discord.TextChannel, *, arg):
message = ctx.message # Get your message
await channel.send(f"{ctx.author}: {arg}") # Send your message
await message.delete() # Delete user message
bot.run('token')

discord.py get webhooks of channel

I'm trying to make a webhook so if anyone says 'ez' it deletes it and sends a message with the webhook with a random message. Originally what I was doing was
if "ez" in message.content:
webhook = await message.create_webhook(name=ctx.author.name)
await webhook.send(ezmessages[random.randint(0, len(ezmessages))-1], username=message.author.name, avatar_url=message.author.avatar_url)
await message.delete()
await webhook.delete()
but the problem is this gets rate limited if webhooks are created and deleted too quickly. So instead what I want to do is check if the bot already has a webhook for the text channel, and if there is one use that but if not use a different one. I thought this would work:
for webhook in message.channel.webhooks:
await webhook.send(ezmessages[random.randint(0, len(ezmessages))-1], username=message.author.name, avatar_url=message.author.avatar_url)
but I get the error
TypeError: 'method' object is not iterable
Even though it should return a list
Anyone know how to correctly iterate over this?
TextChannel.webhooks it's not an attribute, its a function and a coroutine, so you need to call it and await it
webhooks = await message.channel.webhooks()
for webhook in webhooks:
...
docs

How can I delete a message in discord.py after a command was executed by an user?

I am trying to program a function that deletes the message with the command sent by the user.
E.g.:
User sends command /delmes
Bot sends a response to the command
Bot deletes the message sent by the user
Everything I was able to find until now (that would help me) was this Stack Overflow Thread: discord.py delete author message after executing command
But when I used the code, as described in the solutions, I only received AttributeError: 'Bot' object has no attribute 'delete_message'.
The discord.py API Reference (https://discordpy.readthedocs.io/en/latest/migrating.html#models-are-stateful / https://discordpy.readthedocs.io/en/latest/api.html?highlight=delete%20message#message) only revealed that some of the code had changed with newer versions.
So to speak client.delete_message would change to Message.delete(), if I interpreted it correctly!
After changing the code to what I thought it must be I received: NameError: name 'Message' is not defined
This is my code at the very last moment. (I am relatively new to discord.py and only used Python in school)
import discord
from discord.ext import commands
import random
import json
client = commands.Bot(command_prefix = '/', case_insensitive=True)
#client.command(pass_context=True)
async def delcommes(ctx):
await ctx.send("This is the response to the users command!")
await Message.delete(ctx.message, delay=3)
I couldn't understand your question very good but as far as I understand, when command executed, then after bot sends message, you want to delete the command message, in that case it's /delmes. You can use await ctx.message.delete().
#client.command(pass_context=True)
async def delcommes(ctx):
await ctx.send("This is the response to the users command!")
await ctx.message.delete()

Resources