mentioning users with commands

One of my uses for the starboard bot is on results of slash command used by other users. However when the messages show in the starboard, it mentions the bot instead of the user who used the command. It's there any way to change this? I am hosting the bot myself, but I have minimal experience with the discord API and barely enough experience with rust to stub out premium checks. Also, is there a way to restrict usage of the bot to specific users? I searched this server and found mention of blocking users from using commands entirely in a server, but I can't do this because we've got other bots...
20 Replies
circuitsacul
circuitsacul16mo ago
For your first question, I'm not really sure what you mean. Maybe a screenshot would help? For the second, you can use discord's command permissions to lock commands to certain roles.
No description
No description
Efreak #HairForce 1
Efreak #HairForce 1OP16mo ago
Ah. Discord must have either added that recently or not added it on mobile yet. I don't use desktop client much, but I'll check. 👍 As for the first question:
Efreak #HairForce 1
Efreak #HairForce 1OP16mo ago
Using a command:
No description
Efreak #HairForce 1
Efreak #HairForce 1OP16mo ago
Message gets starred, is associated with the bot, not with myself:
No description
Efreak #HairForce 1
Efreak #HairForce 1OP16mo ago
The bot is at the top of the leaderboard, because ~3/4 of messages that would be starred are responses from the bot
No description
circuitsacul
circuitsacul16mo ago
ah, gotcha Since you're hosting the bot, I can give you instructions to modify the code, but I can't help much beyond that assuming it's simple; give me a second to check @Efreak how comfortable are you with rust?
Efreak #HairForce 1
Efreak #HairForce 1OP16mo ago
Not very, unfortunately. I can stub things out. Also, I think the project might not complete with current rust binaries, though I might be thinking of a different discord bot
circuitsacul
circuitsacul16mo ago
no that's this bot, I remember you opened an issue for it I don't really feel up to modifying the bot right now, and to make the changes you want would require a moderate amount of work (even with a hacky solution). And there's not a solution to this problem with the current bot either Sorry I can still provide the steps if you'd like though, but it would require some rust knowledge
Efreak #HairForce 1
Efreak #HairForce 1OP16mo ago
Would appreciate it. If I can't do it, hopefully someone else is interested. If there's something I can do inline, I might be able to do that, as long as there's populated data structures. But I'm not even that familiar with rust syntax lol. IIRC in the js API there's just a different property to check for the message's command user instead of the message author
circuitsacul
circuitsacul16mo ago
k, well, here's a hacky solution that should be simple enough (and should work) Basically, you want to replace the author of the CachedMessage to be the user who invoked the command, rather than the bot user. So mayb esomething like link
-let msg = msg.model().await?;
+let mut msg = msg.model().await?;
+if let Some(inter) = &msg.interaction {
+ msg.author = inter.user.clone();
+}
self.users.insert(msg.author.id, Some(Arc::new((&msg.author).into()))).await;
Some(Arc::new(msg.into()))
-let msg = msg.model().await?;
+let mut msg = msg.model().await?;
+if let Some(inter) = &msg.interaction {
+ msg.author = inter.user.clone();
+}
self.users.insert(msg.author.id, Some(Arc::new((&msg.author).into()))).await;
Some(Arc::new(msg.into()))
This solution will basically replace the author of every bot message with the person who invoked the command; If you want to limit it to the one bot, you can add a check for the author ID This is a lot simpler than I expected it to be lol also, you'll have to fix the compile issue. Try just running cargo update, see if that fixes the compilation problem (and feel free to ping me if you have problems)
Efreak #HairForce 1
Efreak #HairForce 1OP16mo ago
Building is so slow on my underpowered vps 😢
circuitsacul
circuitsacul16mo ago
Hah, yeah I bet
Efreak #HairForce 1
Efreak #HairForce 1OP16mo ago
... It's doing lto, that's why it's taking so long 🤦
circuitsacul
circuitsacul16mo ago
lto?
Efreak #HairForce 1
Efreak #HairForce 1OP16mo ago
Link time optimization
circuitsacul
circuitsacul16mo ago
Ah
Efreak #HairForce 1
Efreak #HairForce 1OP16mo ago
If it's not something you have set up with rust, then it's either a release default or one of my environment variables I build everything with add much optimization as I can, my server has one vcpu and the tradeoff on some software has been worth it, while for simpler programs the build time increase is negligible
circuitsacul
circuitsacul16mo ago
Yeah. For rust, the difference between debug and release is massive by default Wrong reply lol
Efreak #HairForce 1
Efreak #HairForce 1OP16mo ago
And then I've got half a dozen node things running too 😡 I used to run a steam bot, and I'd run six of them under the same process for less heap overhead, but the stuff I'm running now isn't multiple instances of the same thing anymore Now I just need to backup my database for the bot so someone else can host if necessary I've verified that this works as intended, if you have any thoughts of adding it to the main bot (or gating it behind a feature/config setting). I didn't bother to clear my database, but the bot hasn't gained any XP since then (the mentions are correct as well)
circuitsacul
circuitsacul16mo ago
awesome, glad it worked

Did you find this page helpful?