Undefined value - javascript

i have a problem
i entered Unturned or any other game but in output it says about other game
const { ApplicationCommandType } = require('discord.js');
const fetch = require("node-fetch");
const pop = require('popcat-wrapper')
module.exports = {
name: 'steam',
description: "get info about games",
type: ApplicationCommandType.ChatInput,
cooldown: 3000,
options: [
{
name: 'gameinfo',
description: 'get info about a game',
type: 1,
options: [
{
name: 'game',
description: 'Game name',
type: 3,
required: true
}
]
}
],
run: async (client, interaction) => {
const game = interaction.options.get('game')
const gameinfo = await pop.steam(game)
console.log(gameinfo)
}
}
what i got (this is not that game that i entered)
{
type: 'game',
name: 'Touhou Seirensen ~ Undefined Fantastic Object.',
thumbnail: 'https://cdn.akamai.steamstatic.com/steam/apps/1100160/capsule_231x87.jpg?t=1591411698',
description: 'アレは何だ? 鳥か? 妖精か? 謎に満ちた未確認幻想物体が、君を未知の世界に誘う! ファンタスティックでレトロな弾幕シューティング幻想',
website: 'http://www16.big.or.jp/~zun/',
banner: 'https://cdn.akamai.steamstatic.com/steam/apps/1100160/header.jpg?t=1591411698',
developers: [ '上海アリス幻樂団' ],
publishers: [ 'Mediascape Co., Ltd.' ],
price: '12,49€'
}
I'm new to Javascript. And English its not my main language sorry for errors if there's any

i fix it
i added .value:
const game = interaction.options.get("game").value;

Related

MongoDB not saving correct ID | Discord.js 13

So this may just be me being stupid and forgetting a semicolon or something, but I can't seem to resolve this. For my ticket command, I make it so when someone uses the command /ticketsetup and it saves the data of the inputted channels as ID's to then be referenced later. But for some reason, one of them just saves a completely random ID that isn't related to the inputted channel (Transcript)
const {MessageEmbed, CommandInteraction, MessageActionRow, MessageButton} = require('discord.js')
const DB = require('../../Structures/Schemas/TicketSetup')
module.exports = {
name: "ticketsetup",
usage: "/ticketsetup (Admin only)",
description: "Setup your ticketing message.",
permission: "ADMINISTRATOR",
options: [
{
name: "channel",
description: "Select the ticket creation channel.",
required: true,
type: "CHANNEL",
channelTypes: ["GUILD_TEXT"]
},
{
name: "category",
description: "Select the ticket channel's category.",
required: true,
type: "CHANNEL",
channelTypes: ["GUILD_CATEGORY"]
},
{
name: "transcripts",
description: "Select the transcripts channel.",
required: true,
type: "CHANNEL",
channelTypes: ["GUILD_TEXT"]
},
{
name: "handlers",
description: "Select the ticket handler's role.",
required: true,
type: "ROLE"
},
{
name: "description",
description: "Set the description of the ticket creation channel.",
required: true,
type: "STRING"
}
],
/**
*
* #param {CommandInteraction} interaction
*/
async execute(interaction) {
const {guild, options} = interaction
try {
const Channel = options.getChannel("channel")
const Category = options.getChannel("category")
const Transcripts = options.getChannel("transcripts")
const Handlers = options.getRole("handlers")
const Description = options.getString("description")
await DB.findOneAndUpdate({GuildID: guild.id},
{
ChannelID: Channel.id,
Category: Category.id,
Transcripts: Transcripts.id,
Handlers: Handlers.id,
Everyone: guild.id,
Description: Description,
},
{
new: true,
upsert: true
}
);
const Embed = new MessageEmbed().setAuthor({
name: guild.name + " | Ticketing System",
iconURL: guild.iconURL({dynamic: true})
})
.setDescription(Description)
.setColor("#36393f")
const Buttons = new MessageActionRow()
Buttons.addComponents(
new MessageButton()
.setCustomId("ticket")
.setLabel("Create Ticket!")
.setStyle("PRIMARY")
.setEmoji("🎫")
)
await guild.channels.cache.get(Channel.id).send({embeds: [Embed], components: [Buttons]})
interaction.reply({content: "Done", ephemeral: true})
} catch (err) {
const ErrEmbed = new MessageEmbed().setColor("RED")
.setDescription(`\`\`\`${err}\`\`\``)
interaction.reply({embeds: [ErrEmbed]})
}
}
}
Schema Model:
const {model, Schema} = require('mongoose')
module.exports = model("TicketSetup", new Schema({
GuildID: String,
Channel: String,
Category: String,
Transcripts: String,
Handlers: String,
Everyone: String,
Description: String,
}))

How do I specify options for commands?

I want to specify choices for an option for my command in Discord.js. How do I do that?
The command:
module.exports = {
name: 'gifsearch',
description: 'Returns a gif based on your search term.',
options: [{
name: 'type',
type: 'STRING',
description: 'Whether to search for gifs or stickers.',
choices: //***this is the area where I have a question***
required: true
},
{
name: 'search_term',
type: 'STRING',
description: 'The search term to use when searching for gifs.',
required: true,
}],
async execute(interaction) {
let searchTerm = interaction.options.getString('search_term')
const res = fetch(`https://api.giphy.com/v1/gifs/search?q=${searchTerm}&api_key=${process.env.giphyAPIkey}&limit=1&rating=g`)
.then((res) => res.json())
.then((json) => {
if (json.data.length <= 0) return interaction.reply({ content: `No gifs found!` })
interaction.reply({content: `${json.data[0].url}`})
})
},
};
I have read the discord.js documentation/guide and I know about the .addChoice() method, but it doesn't look like that will be compatible with my bot's current code.
The discord.js api describes this as ApplicationCommandOptionChoices.
So you basically just insert an array of this in your choices.
module.exports = {
...
choices: [
{
name: "name to display",
value: "the actual value"
},
{
name: "another option",
value: "the other value"
}
]
...
};

Discord.js Slash commands name invalid

I have an issue with discord.js slash commands.
As you can see in my code I am setting the name to "Name" and "Age" so I don't understand what the issues are.
This is my error:
error: (node:16004) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
options[0].name: Command name is invalid
And this is my code:
const Discord = require('discord.js');
require("dotenv").config();
const client = new Discord.Client();
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
const getApp = (guildid) => {
const app = client.api.applications(client.user.id);
if(guildid){
app.guilds(guildid);
}
return app;
}
await getApp("842486032842358784").commands.post({
data: {
name: 'embed',
description: 'Displays embed',
options: [
{
name: 'Name',
description: 'Your Name',
required: true,
type: 3
},
{
name: 'Age',
description: 'Your Age',
required: false,
type: 4
}
]
},
})
client.ws.on('INTERACTION_CREATE', async(interaction) => {
const command = interaction.data.name.toLowerCase();
const { name, options } = interaction.data;
console.log(options);
if(command === "embed"){
reply(interaction, 'hi');
}
})
const reply = (interaction, response) => {
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: {
content: response,
}
}
})
}
});
client.login(process.env.TOKEN);
The option names should be all lowercased, in your case, substitute "Name" with "name" and "Age" with "age". That should work. The code is below:
const Discord = require('discord.js');
require("dotenv").config();
const client = new Discord.Client();
client.on('ready', async() => {
console.log(`Logged in as ${client.user.tag}!`);
const getApp = (guildid) => {
const app = client.api.applications(client.user.id);
if (guildid) {
app.guilds(guildid);
}
return app;
}
await getApp("842486032842358784").commands.post({
data: {
name: 'embed',
description: 'Displays embed',
options: [{
name: 'name',
description: 'Your Name',
required: true,
type: 3
},
{
name: 'age',
description: 'Your Age',
required: false,
type: 4
}
]
},
})
client.ws.on('INTERACTION_CREATE', async(interaction) => {
const command = interaction.data.name.toLowerCase();
const {
name,
options
} = interaction.data;
console.log(options);
if (command === "embed") {
reply(interaction, 'hi');
}
})
const reply = (interaction, response) => {
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: {
content: response,
}
}
})
}
});
client.login(process.env.TOKEN);

react TypeError: Cannot read property 'type1' of undefined

I'm studying the react-beautiful-dnd example, and I want to add a conditional repulsion of an element, but I get an error that the field cannot be read.
This data
const initialData = {
tasks: {
'task-1': { id: 'task-1', content: 'Take out the garbage',type1: 'w' },
'task-2': { id: 'task-2', content: 'Watch my favorite show',type1: 'a' },
'task-3': { id: 'task-3', content: 'Charge my phone',type1: 'h' },
'task-4': { id: 'task-4', content: 'Cook dinner',type1: 'w' }
},
columns: {
'column-1': {
id: 'column-1',
title: 'To do',
type2: 'all',
taskIds: ['task-1', 'task-2', 'task-3', 'task-4']
},
'column-2': {
id: 'column-2',
title: 'In progress',
type2: 'w',
taskIds: []
},
'column-3': {
id: 'column-3',
title: 'Done',
type2: 'a',
taskIds: []
}
},
// Facilitate reordering of the columns
columnOrder: ['column-1', 'column-2', 'column-3'] }export default initialData
so they are connected
import initialData from './initial-data'
so it is assigned in state
state = initialData
this is how it is used and everything that I described it works and this is the code from the example
const start = this.state.columns[source.droppableId]
const finish = this.state.columns[destination.droppableId]
if (start === finish) {
const newTaskIds = Array.from(start.taskIds)
now below i want to add my condition and it throws an error
const typeDrag = this.state.tasks[source.draggableId]
const typeDrop = this.state.columns[destination.droppableId]
if(typeDrag.type1!==typeDrop.type2)
{return}
and I don't understand why start.taskIds works, but typeDrag.type1 reports that there is no such field
similarly executable codesandbox example
example
Solution:
instead of: const typeDrag = this.state.tasks[source.draggableId]
use: const typeDrag = this.state.tasks[draggableId]
Explanation:
In your code source doesn't have property draggableId.
So typeDrag is undefined because source.draggableId is undefined.
Argument of your onDragEnd hook looks like that:
{
"draggableId": "task-2",
"type": "TASK",
"source": {
"index": 1,
"droppableId": "column-1"
},
"destination": {
"droppableId": "column-2",
"index": 0
},
"reason": "DROP"
}
By checking your sandbox sample I see that you've already extracted draggableId property to a constant from the method argument ("result"):
const { destination, source, draggableId } = result; // line:28
So using draggableId instead of source.draggableId resolves TypeError: Cannot read property 'type1' of undefined.

How do I create a master/root schema with normalizr 2?

Say I have the following schemas and data:
const user = new schema.Entity('users')
const video = new schema.Entity('videos', {
user
})
const comment = new schema.Entity('comments', {
video
})
// Sample Data
const users = [
{ id: 1, object: "User", name: "User 1" },
{ id: 2, object: "User", name: "User 2" },
]
const videos = [
{ id: 1, object: "Video", user: users[0] },
{ id: 2, object: "Video", user: users[1] },
]
const comments = [
{ id: 1, object: "Comment", video: videos[0] },
{ id: 2, object: "Comment", video: videos[0] },
]
How would I setup a resource and resourceList schema to wrap all my schemas so that in my api calls I would only ever have to reference resource or resourceList eg:
api.videos.list().then(
// response.data is an array containing multiple videos
response => normalize(response.data, resourceList)
)
// entities: { videos: [...], users: [...] }
or
api.videos.retrieve(videoId).then(
// response.data is an object containing a single video
response => normalize(response.data, resource)
)
I've tried doing this:
const resource = {
user,
video,
}
const resourceList = new schema.Array(resource, inferSchema)
function inferSchema({ object: objectName = '' }) {
return objectName.charAt(0).toLowerCase() + objectName.slice(1)
}
But that didn't seem to work.

Categories

Resources