I'm making a discord bot and am using discord v14.3.0.
I call const faction = interaction.options.getString(`${date}-faction`)
with let date = Date.now()
above it. I am calling this in a module with async execute(interaction) {}
and call that module in bot.js like this:
// if interaction is from bot
if (!interaction.isCommand()) return;
const slashCom = client.slashCommands.get(interaction.commandName);
if (!slashCom) return;
try {
await slashCom.execute(client, interaction);
} catch(e) {
console.error(e);
await interaction.reply({ content: 'There was an error while executing this
command!', ephemeral: true });
}
inside a client on interaction create. The application command data is this:
data: new SlashCommandBuilder()
.setName('faction')
.setDescription('Choose a faction to join.')
.addStringOption(option =>
option.setName(`${date}-faction`)
.setDescription('The faction you want to join. (BurningShadows, WaterLight, or JadeDawn.)')
.setRequired(true)
.addChoices({
name: "BurningShadows", value: "BurningShadows" },
{ name: "WaterLight", value: "WaterLight" },
{ name: "JadeDawn", value: "JadeDawn" })
),
I have tried the other article on this but I did not find anything that solved my problem. What console.log(interaction.options)
prints out is this:
{
intents: 46687,
closeTimeout: 5000,
waitGuildTimeout: 15000,
shardCount: 1,
makeCache: [Function (anonymous)],
partials: [],
failIfNotExists: true,
presence: { status: 'online', user: { id: null } },
sweepers: { threads: { interval: 3600, lifetime: 14400 } },
ws: {
large_threshold: 50,
compress: false,
properties: { os: 'darwin', browser: 'discord.js', device: 'discord.js' },
version: 10,
presence: { activities: [], afk: false, since: null, status: 'online' }
},
rest: {
agent: [Getter],
api: 'https://discord.com/api',
authPrefix: 'Bot',
cdn: 'https://cdn.discordapp.com',
headers: {},
invalidRequestWarningInterval: 0,
globalRequestsPerSecond: 50,
offset: 50,
rejectOnRateLimit: null,
retries: 3,
timeout: 15000,
userAgentAppendix: 'Node.js v16.17.0',
version: '10',
hashSweepInterval: 14400000,
hashLifetime: 86400000,
handlerSweepInterval: 3600000
},
jsonTransformer: [Function: toSnakeCase],
shards: [ 0 ]
}
Any help is greatly appreciated!
The option name is set to the current date when it is created, then you try to get it using Date.now()
which will have a different value by that time.
I had this issue before but fixed it by changing getString()
to just get()
.