Here is my configuration file.
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity({ name: 'guild_configurations' })
export class GuildConfiguration {
@PrimaryGeneratedColumn()
id: number;
@Column({ unique: true, name: 'guild_id' })
guildId: string;
@Column({ default: '?' })
prefix: string;
@Column({ name: 'welcome_channel_id', nullable: true })
welcomeChannelId: string;
}
I was trying to add search guildId with discord guild.id
// https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-guildCreate
import { Guild } from 'discord.js';
import BaseEvent from '../utils/structures/BaseEvent';
import DiscordClient from '../client/client';
import { getRepository, ObjectID } from 'typeorm';
import { GuildConfiguration } from '../typeorm/entities/GuildConfiguration';
export default class GuildCreateEvent extends BaseEvent {
constructor(
private readonly guildConfigRepository = getRepository(GuildConfiguration)
) {
super('guildCreate');
}
async run(client: DiscordClient, guild: Guild) {
console.log("Hello World");
console.log(`Joined ${guild.name}`);
const config = await this.guildConfigRepository.findOne({guildId:guild.id});
if(config){
console.log("A configuration was found!")
}else{
console.log("Configuration was not found. Creating one...")
const newConfig = this.guildConfigRepository.create({guildId:guild.id})
return this.guildConfigRepository.save(newConfig);
}
}
}
this.guildConfigRepository.findOne({guildId:guild.id}); it shows
Argument of type '{ guildId: string; }' is not assignable to parameter of type 'FindOneOptions'. Object literal may only specify known properties, and 'guildId' does not exist in type 'FindOneOptions'.ts(2345)
my typeorm version is "typeorm": "^0.3.1" Does anyone know how to fix this? Thanks!
this.guildConfigRepository.findOne({ where: { guildId: guild.id } });
? – Silencer