emily-the-geek
emily-the-geek

Reputation: 23

How to make my Discord bot respond to both custom prefixes and mentions when I use a function to get the prefix?

I would like to preface this with saying that I asked this question previously and it got closed, marked as a duplicate. I saw those other questions before. I tried those solutions. They didn't work. They don't work with prefix functions, only prefix strings. This is why I asked the question. I have reworded a few things, added info to the title, as much as I can think of to get this question through so I can get the answer I need. Please, please do not close this one. I want an answer that works.

I have a function that retrieves a custom prefix from a database file, but I would like to implement the ability to also respond to mentions, as in the when_mentioned() function. However, I can not pass in both functions to the command_prefix parameter when I am initializing my bot, nor can I add my prefix function to the when_mentioned_or() function to combine the two. Is there any way I could go about doing this? I've been searching for answers for the last hour and have found nothing that works yet.

Upvotes: 1

Views: 669

Answers (1)

Harmon758
Harmon758

Reputation: 5157

You can simply use the when_mentioned function in your own function that retrieves a custom prefix. You can call it with the same bot and msg that you're passed and it will return a list of the mention formats (for with and without a nickname) that you can use. You can then return that list with your custom prefix appended.

Alternatively, you can simply directly return a list with your custom prefix, bot.user.mention (see the documentation for Bot.user and ClientUser.mention), and the nickname format for that mention (<@!{user_ID}> rather than <@{user_ID}>; see the documentation for ClientUser.id).

Upvotes: 1

Related Questions