I'm starting to work with discord API via discord.py module. I've been through docs, but I've not found anything like this.
So, here's the question:
Is there some event trigger like onFirendRequestAccepted which runs the function when someone accept your friend request?
The below is outdated since v2.0 of discord.py, which removes the 3 events listed.
Old answer:
The rewrite branch contains on_relationship_add, on_relationship_remove and on_relationship_update.
http://discordpy.readthedocs.io/en/rewrite/api.html?highlight=friend#discord.on_relationship_add
Related
I'm using Hikari + Lightbulb to create my first discord bot and I'm using this as an opportunity to learn as much as possible. As mentioned in the title, I just want to learn how to use
add_reaction(":smile:") correctly. I've read through the Hikari documentation and to be honest, I am having difficulties understanding it fully. I thought the correct line of code would be something along the lines of this
#bot.listen(hikari.MessageCreateEvent)
async def message(event):
print(event.content)
await message.add_reaction(":smile:")
When I go to run this code I receive the following error: AttributeError: 'GuildMessageCreateEvent' object has no attribute 'add_reaction'. This is making think my error lies with using the MessageCreateEvent object but after reading the documentation I can't tell which object does support this attribute. Is there something I'm missing? Or am I simply not using the attribute correctly and it's meant to be used in some other way?
Okay so I've managed to figure it out with Help from the comments (Thank you Guimoute).
I needed to include event. before the message.add_reaction.
Just in case anyone has had a similar issue this is the complete code that worked for me
#bot.listen(hikari.MessageCreateEvent)
async def message(event):
print(event.content)
await event.message.add_reaction(emoji="👍")
Keen eyed among you will notice I had to change the end. If you don't be specific and and use emoji="" is will tell you that the value is not snowflake, I don't fully understand it but reading over some of the discord dev portal documentation, I think it's a requirement of discord.
I'm making a Discord bot in Python and I want to add a feature, when message can be seen only by one user.
I made an example from Dank Memer bot. Any ideas?
These are called Ephemeral messages, however, they can only be used in response to an interaction. Examples of interactions are things like slash commands (like mentioned above), drop-down menus, and buttons.
Unfortunately, the current version of discord.py does not support interactions, so you will have to use a different library.
You can check out some cool libraries for interactions. I would personally recommend discord-components, but that's just my opinion.
You can now do this, for anyone googling:
await interaction.response.send_message(f"only you, {interaction.user}, can see this!", ephemeral=True)
I have coded a discord bot with discord.py, it can basically create Vcs and deletes them after no one is in them anymore. Also users can change the name of the channel with an extra text-channel created for the vc they are in. The thing is tho, after 3 times of changing it, the code breaks right at the await channel.edit(name = newchannelname) and stops completely. I checked and everything is working up to that point, so all of my mechanisms of finding the right channel and everything with the name, all is working. Does aynone know what the problem could be?
I´m hosting the bot on replit.com
There appears to be an undocumented Discord API limit for editing channels, as documented in this 2020 GitHub issue:
There appears to be an entirely undocumented (and unreported in the API) rate limit of 2 channel renames/10 minutes. The first two name changes go through fine, ...
Probably not a coincidence that it also caps at two, unless there's a separate error message you haven't specified or you can identify another piece of code creating the issue within the function that isn't related to API calls.
Most likely, you will have to figure out an alternate solution that doesn't rely on that specific API call: perhaps specifying the channel name at initialization or a separate optional command that must be run before the channel creation?
I am working on a application, where it would be cool to change the Status of your Discord User you are currently logged in to. For example when i start the appplication then the Status should change to something like "Playing Program" and when you click on the User's Status then it should display the Image of the Program.
Now i wanted to ask if this is somehow possible to make and in which programming Languages is it makeable?
EDIT: Solved the Problem with pypresence
The question is not if a certain programming language can do this, but if the Discord API can do it or if you have to use other ways than the official API.
I would advise you to take a closer look at https://discordapp.com/developers/docs/intro first.
In your startup, where DiscordSocketClient is available, you can use SetGameAsync(). This is for C# using Discord.NET.
To answer your question, I think any wrapper for Discord's API allows you to set the current playing game.
For our company I'd like to have a Python based IRC bot which checks whether the websites of our clients are still up and running. More specific: I want to list a number of URL which should be visited every, say, 15 minutes. If it fails, the URL should be checked again after 5 minutes. If retrieving the URL still doesn't result in an HTTP status code 200, it should echo the failing URL in the channel so we can investigate it.
I've written a plugin for Supybot some time ago that basically does some of the above in a crude but effective way. If I want to expand the functionality of the current code to the above 'specs' I need to do some major refactoring; basically it would mean starting from scratch.
Which raises the question: should I write a better plugin for Supybot, matching the new requirements, or go for something else altogether? Should I start from scratch (learning the most, implementing the relevant RFCs myself, spending more time than planned) or is there a suitable framework which handles the basic IRC stuff?
I vote for a completely new plugin for Supybot. Learn more ;)
If you won't do so much, try python irclib. It's a (still maintained) python lib for IRC.
Twisted may also be ok, but it's a little but too much...
To me it sounds like a case of your application wanting to talk IRC, and my gut reaction would be to use Twisted, which has IRC clients. This may or may not be the right solution for you, but at least it's worth investigating.
I finally decided to create use Twisted for my bot. As to the why:
Supybot already has a lot of functionality. And that can be a good thing: just create a simple plugin, hook it up and start using the bot. The downside is that you may not like some of the functionality already provided for. As an example: I didn't like the fact that it responded to everything (Error: "foo" is not a valid command.). I'm sure it can be turned off somehow somewhere, but these kind of small things bothered me.
The Python IRC client library on the other hand felt a little too bare bones. Especially since I needed threading to have the bot check a whether a number of websites are still alive while remaining responsive in the channel.
If the irclib felt like too low level, writing a bot from scratch would certainly be. While I definitely wanted to learn something, I also wanted to focus on the actual functionality of the bot, without being bothered too much by the 'basic' stuff (e.g. I don't necessarily want to write the code to identify the bot, I like to just have some configuration setting to store the nickname and password and handle this for me.)
Twisted has a nice example of a logging bot which can be used as a starting point. Furthermore: in the future it should not be too hard to write a small webserver (using Twisted obviously) to display the output of the bot.
Tip: besides the Twisted documentation you can also take a look at the October 2008 issue of Python Magazine for the article "A Twisted Logging Server" by Doug Farrell.
Thanks to the ones who answered the question. You set me on the right track. :)
Writing a simple IRC bot isn't that hard. I have a template I keep using for my bots, which range from SVN bots to voting-status bots to bots which check connections to certain IPs and change the channel's topic according to the result.
I can share the source if you'd like, though there's nothing like writing your own :)
irc3 is a plugable irc client library based on asyncio and venusian https://irc3.readthedocs.org/