Discord bot that moves people based on game activity - discord.js

Hello everyone I'm new to coding but I want to code the bot mentioned in the title so my questions are:
-Is there a command that reads the game activity?
-What is the command that makes the bot move someone?
I set the basics up but don't really know where to go from here:
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Online');
});
client.login('*the token*');

All of a user's game activities are stored as an array, activities, within the presence property of your user object.
For example, if you want to get the game statuses of the author of a message, you can use <message>.author.presence.activities to get that array. However, since a user may have multiple statuses (custom statuses, games, Rich Presences, etc), you'll generally want to get a specific activity.
If you need to check if the name of the status is a certain one, you'll need to get the specific index first, such as <message>.author.presence.activities[0].name. If you want to check each status and see if any of them align with a needed name, you can use a for...of loop.
For more information, here is the documentation on the presence of a user.
As for "moving someone," you are not giving any more explanation as to what you mean, so that should be implemented once your bot can properly detect certain games.
In the meantime, try following a guide on how to turn user input into actual commands, and then this may make more sense if you are still facing issues.

Related

Nextcord: I want to mention the sender of the slash command I made. How would I go about that?

I'm trying to make this command notify my admins of a bot test and need it to mention the user who called the command. How would I go about that? I don't fully understand how to get that information with slash commands.
#client.slash_command(name= "test", description="(For Deputies or Leader only) Checks the operational state of the client.", guild_ids=[806043206030589952])
#has_any_role(leader_id, deputy_id)
async def test(interaction:Interaction):
bot_log = channel_up(940125176723554394)
await bot_log.send(f'<#&806045254834847776>,{} has started diagnostics for the bot. Please ignore any possible disturbances for the next minute or so.')
Thanks in advance for the advice, it's the first discord bot I've ever created.
EDIT:
In documentation, I found the solution. I have to use interaction.user.mention to get it to mention the user who sent the command. Or at least in theory, I'm dealing with a different issue now. Hopefully this helps people who also were as confused as me out.
You can use the interaction.user.name function with an # at the beginning.
The code should look something like this:
await interaction.response.send_message("#"+str(interaction.user.name))

Discord.py adding reaction to webhook.send message

I am able to send messages to my discord channel via webhook very easily, however, when trying to add reactions to the messages it's very difficult, considering my programming is still trivial.
The code line I have right now is:
data_count=1
webhook.send(content=discord.Reaction(message="test", data=data_count, emoji="👍"), file=discord.File("american_eagle_excited.gif"), embed=discord.Embed(title="Sample Embed", description="This is the description"))
Everything, when I break down the parameters I can get to work besides the discord.Reaction class. I feel like I am missing something very easily and after trying to read through the class requirements I had to finally make my way to StackOverflow.
To add a reaction you need the discord.Message instance which is returned by the webhook.send method, you then add the reaction with message.add_reaction
message = webhook.send("test", wait=True, ...) # `wait=True` is really important, if we don't set this the bot will not wait for the message to be returned
await message.add_reaction("👍")

Discord bot how would i make the bot check for server ownership

I'm trying to make commands that are exclusive to the guild's owner, how would i check that? The closest of what i want is the ADMINISTRATOR permission but not owner
D Pardal's answer is 100% correct.
I'm not sure how familiar with the docs you are, but it could be helpful to start getting a feel for how to find things like that from the Discord.js docs. It, at least for me, helps to gain an understanding of just what every object/class they provide does. If you already know this, and just had a bit of a mental block, just ignore this & have a nice day. Otherwise, I'm waiting on a question of my own, so I figured I'd help out with what I know. I invite you to step through the docs at Discord.js.org with me as I explain this to see exactly what I'm talking about. Until recently, I found the Discord.js.org docs crazily complicated and un-understandable, so I'm hoping I can make it a little easier for you, and anyone else down the line, who could benefit from them.
Something to glean from this is that data about members in a guild can be found in the Guild object representing the guild. How do we find that?
Well, the only place we have to start is (probably, assuming your bot just takes in messages and executes commands based on them) the message we take in, we'll call it message. Going to the Discord.JS docs, scrolling through the Classes on the side, eventually we see that there is, in fact, a Message class!
Now we can look and see what data ships with it, which is a wide variety of things that may be useful to you down the road. If we look close enough, the Message obj does have a property that sounds like what we're looking for, Message.Guild! The docs say that property is of of type Guild, & clicking the hyperlink, it takes us to the class definition for a Guild.
According to the definition, a Guild object represents a Guild on discord, so with any luck, we can get some information about things in said guild. Knowing that we're looking for a specific member in the guild, we might be tempted to look into the Guild#members property- and while that could be useful down the line, it doesn't get us
particulaly close to knowing who the owner is, just who all the members are.
Finally, if we scroll a bit further, we see that the Guild Class has a property called Owner, AND ownerID! Depending on what we want, either could be useful. Owner is a GuildMember object, a representation of a user that contains a lot of details (just like how a Guild object is a representation of a guild with lots of info about it). However, if we just need the ID for something like, say, checking the ID of the command sender to the ID of the owner, we can just get the ID property of the owner object.
In an expanded form you could visualize that like such
const guild = message.guild
const ownerID = guild.ownerID
Or condensed like
const ownerID = message.guild.ownerID
If there's anything I can clarify further let me know! I know I couldn't figure out the docs for the longest time, so I hope this helped at least somewhat.
Just use Guild#owner, like this:
msg.member.id === msg.guild.ownerID // Returns true if the message was sent by the guild owner.

How do I make it so people can't vote twice on a Discord poll system?

I have a Discord Bot which has a poll system. The Discord bot can create multiple polls and store the data in a .json file. The only problem with this is people can vote twice for a single poll. How do I make it so a person can't vote twice for a single poll? This may seem like a simple question, however, I can't find a way to solve this.
Create an array in the JSON file called "voted" and whenever someone votes, add their Discord ID to the array. Whenever someone tries to vote, check if their ID already exists in the "voted" array.
NOTE: This will not prevent users from creating spam accounts just to vote.

Clear previous Alexa Cards

Is there a way to tell Alexa to either remove previous cards when I send a new one?
I have an skill which sends kind of a status each time you run a command, and typical use case is to do multiple actions in a session, each of which I'd like to send a card. It gets really cluttered since they all just add on to each other. I'd like to just either update the first card, or remove it and make a new one each time.
That is not possible with the current API. I think anyone using skills is already used to the flood of cards that come after each interaction.

Resources