Oct 11, 2021 01:21 PM
I have a discord bot written in javascript using autocode. When a user joins my discord server, my bot updates my airtable table called discord. I have another table linked to the discord table, called defense. The defense uses the discord fields of ID, User ID, Username, and Role from the Discord table. The defense table has some other fields which the user should be able to update later.
How do I get the Defense table to update with the new users when they join the server? Right now, I insert a record into the Discord table with the user info. But even though the two tables are linked together, the Defense table is not updating with the new users info.
Oct 11, 2021 02:07 PM
Welcome to the Airtable community!
Airtable does not create new records unless it is told to create a new record. There are several ways to tell Airtable to create a new record.
It sounds like you want the system to create two linked records, and your bot currently creates one using the REST api.
You could have your bot use the info returned by the rest api to create the second linked record.
Or, you could have an Airtable automation create the second linked record whenever a record is created in the first table.
Oct 11, 2021 02:26 PM
My bot uses the following code to create the record when the user joins my server.
Blockquote
if (checkdb.rows.length == 0){
let memberadd = await lib.airtable.query[’@1.0.0’].insert({
table:Discord
,
fieldsets: [
{
‘Username’:${event.user.username}
,
‘Nick’:${event.nick}
,
‘User_ID’:${event.user.id}
,
‘Discriminator’:${event.user.discriminator}
,
‘Joined’:${event.joined_at}
}
],
typecast: false
});
}
Username and UserID are both shared with the other table.
What should I do to make the other table actually update with the shared data? I haven’t done this with airtable before, so please treat me like I’m completely stupid and walk me though it.
Oct 11, 2021 02:44 PM
I’m not familiar with the platform that you are using to create the Airtable records.
However, in general you would create the second record in the same way, only you would provide the other table and the fieldset would have a different set of fields that includes the linked record field. The value of the linked record field would be based on the record id returned when you created the first record. You may need to play around with the exact format (e.g. array versus string). I don’t use the REST API that often and don’t have those formats memorized.