C
C#โ€ข8mo ago
PolishDywan

Discord Module

Hello! I got a Discord module for a server script on GTAV. Unfortunately, it doesn't run on Ubuntu... Everything works fine on Windows. I have the correct path and permissions. Code:
public static void StartBotProcess()
{
try
{
KillBotProcess();

g_BotProcess = new Process();
g_BotProcess.StartInfo.FileName = Path.Combine(Directory.GetCurrentDirectory(), "netcoreapp3.1", Helpers.FormatString("DiscordBot{0}", RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""));

#if !DEBUG || RUN_DISCORD_BOT_IN_DEBUG
g_BotProcess.StartInfo.RedirectStandardOutput = true;
g_BotProcess.StartInfo.RedirectStandardError = true;
g_BotProcess.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
g_BotProcess.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
g_BotProcess.StartInfo.UseShellExecute = false;
#else
g_BotProcess.StartInfo.UseShellExecute = true;
#endif
g_BotProcess.Start();

#if !DEBUG || RUN_DISCORD_BOT_IN_DEBUG
g_BotProcess.BeginOutputReadLine();
g_BotProcess.BeginErrorReadLine();
#endif
}
catch
{

}
}
public static void StartBotProcess()
{
try
{
KillBotProcess();

g_BotProcess = new Process();
g_BotProcess.StartInfo.FileName = Path.Combine(Directory.GetCurrentDirectory(), "netcoreapp3.1", Helpers.FormatString("DiscordBot{0}", RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""));

#if !DEBUG || RUN_DISCORD_BOT_IN_DEBUG
g_BotProcess.StartInfo.RedirectStandardOutput = true;
g_BotProcess.StartInfo.RedirectStandardError = true;
g_BotProcess.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
g_BotProcess.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
g_BotProcess.StartInfo.UseShellExecute = false;
#else
g_BotProcess.StartInfo.UseShellExecute = true;
#endif
g_BotProcess.Start();

#if !DEBUG || RUN_DISCORD_BOT_IN_DEBUG
g_BotProcess.BeginOutputReadLine();
g_BotProcess.BeginErrorReadLine();
#endif
}
catch
{

}
}
Error on startup:
No file or directory
No file or directory
26 Replies
pan Scott
pan Scottโ€ข8mo ago
idk try to output file path somehow and see if it's correct
arion
arionโ€ข8mo ago
What does this method do?
Helpers.FormatString("DiscordBot{0}",
just string.Format? Also you might wanna use AppContext.BaseDirectory over Directory.GetCurrentDirectory();
PolishDywan
PolishDywanโ€ข8mo ago
GitHub
V/Source/DiscordBot at main ยท OwlGamingCommunity/V
OwlGaming roleplay script for RAGE Multiplayer on GTA 5. - OwlGamingCommunity/V
PolishDywan
PolishDywanโ€ข8mo ago
PolishDywan
PolishDywanโ€ข8mo ago
This is all code ๐Ÿ˜” I can pay for your helpp
arion
arionโ€ข8mo ago
Try changing the
g_BotProcess.StartInfo.FileName = Path.Combine(Directory.GetCurrentDirectory(), "netcoreapp3.1", Helpers.FormatString("DiscordBot{0}", RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""));
g_BotProcess.StartInfo.FileName = Path.Combine(Directory.GetCurrentDirectory(), "netcoreapp3.1", Helpers.FormatString("DiscordBot{0}", RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""));
to
g_BotProcess.StartInfo.FileName = Path.Combine(AppContext.BaseDirectory, "netcoreapp3.1", Helpers.FormatString("DiscordBot{0}", RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""));
g_BotProcess.StartInfo.FileName = Path.Combine(AppContext.BaseDirectory, "netcoreapp3.1", Helpers.FormatString("DiscordBot{0}", RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""));
It might simply be a working directory issue
PolishDywan
PolishDywanโ€ข8mo ago
Same :/
INNEREXCEPTION: None
MESSAGE: No such file or directory
SOURCE: System.Diagnostics.Process
EXSTACK: at bool System.Diagnostics.Process.ForkAndExecProcess(string filename, string[] argv, string[] envp, string cwd, bool redirectStdin, bool redirectStdout, bool redirectStderr, bool setCredentials, uint userId, uint groupId, uint[] groups, out int stdinFd, out int stdoutFd, out int stderrFd, bool usesTerminal, bool throwOnNoExec)
ENVSTACK: at System.Environment.get_StackTrace()
at Core.HandleServerException(Exception ex)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at Core.HandleServerException(Exception ex)
at Core.<.ctor>b__52_1(Object sender, FirstChanceExceptionEventArgs eventArgs)
at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at DiscordBotIntegration.StartBotProcess()
at PlayerAdminCommands.General.StartDiscordBot(CPlayer SenderPlayer, CVehicle SenderVehicle)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at CommandManager.OnPlayerRawCommand(CPlayer a_Player, String msg)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
INNEREXCEPTION: None
MESSAGE: No such file or directory
SOURCE: System.Diagnostics.Process
EXSTACK: at bool System.Diagnostics.Process.ForkAndExecProcess(string filename, string[] argv, string[] envp, string cwd, bool redirectStdin, bool redirectStdout, bool redirectStderr, bool setCredentials, uint userId, uint groupId, uint[] groups, out int stdinFd, out int stdoutFd, out int stderrFd, bool usesTerminal, bool throwOnNoExec)
ENVSTACK: at System.Environment.get_StackTrace()
at Core.HandleServerException(Exception ex)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at Core.HandleServerException(Exception ex)
at Core.<.ctor>b__52_1(Object sender, FirstChanceExceptionEventArgs eventArgs)
at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at DiscordBotIntegration.StartBotProcess()
at PlayerAdminCommands.General.StartDiscordBot(CPlayer SenderPlayer, CVehicle SenderVehicle)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at CommandManager.OnPlayerRawCommand(CPlayer a_Player, String msg)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
arion
arionโ€ข8mo ago
Could you change it to this next?
g_BotProcess.StartInfo.FileName = Path.Combine(AppContext.BaseDirectory, Helpers.FormatString("DiscordBot{0}", RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""));
g_BotProcess.StartInfo.FileName = Path.Combine(AppContext.BaseDirectory, Helpers.FormatString("DiscordBot{0}", RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : ""));
PolishDywan
PolishDywanโ€ข8mo ago
same error ๐Ÿ˜ฆ
arion
arionโ€ข8mo ago
Can you screenshot your output folder?
PolishDywan
PolishDywanโ€ข8mo ago
No description
PolishDywan
PolishDywanโ€ข8mo ago
Windows
PolishDywan
PolishDywanโ€ข8mo ago
Linux:
No description
PolishDywan
PolishDywanโ€ข8mo ago
@arion ๐Ÿ™‚
arion
arionโ€ข8mo ago
That explains why You built the project on windows try rebuilding it for linux On windows it looks for DiecordBot.exe on Linux it looks for DiscordBot which is an elf binary (Linux program) either build it on Linux using dotnet build or build it on windows for Linux using dotnet build --os linux
PolishDywan
PolishDywanโ€ข8mo ago
No description
PolishDywan
PolishDywanโ€ข8mo ago
Okay, but I have a few items in my solution. How to make it compile exactly only DiscordBot? ๐Ÿ™‚
arion
arionโ€ข8mo ago
from the command line you can do the same commands, just cd into that folder (The DiscordBot folder) and build it from there
PolishDywan
PolishDywanโ€ข8mo ago
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\Users\eoeo2\Desktop\RageMP\Source\DiscordBot> dotnet build --os linux
MSBuild version 17.7.3+4fca21998 for .NET
Projects to be restored are being identified...
All designs are up to date for restoration.
DiscordBot -> C:\Users\eoeo2\Desktop\RageMP\Output\Debug\netcoreapp3.1\linux-x64\DiscordBot.dll

Compilation succeeded.
Warnings: 0
Number of errors: 0

Elapsed time: 00:00:01.99
PS C:\Users\eoeo2\Desktop\RageMP\Source\DiscordBot>
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\Users\eoeo2\Desktop\RageMP\Source\DiscordBot> dotnet build --os linux
MSBuild version 17.7.3+4fca21998 for .NET
Projects to be restored are being identified...
All designs are up to date for restoration.
DiscordBot -> C:\Users\eoeo2\Desktop\RageMP\Output\Debug\netcoreapp3.1\linux-x64\DiscordBot.dll

Compilation succeeded.
Warnings: 0
Number of errors: 0

Elapsed time: 00:00:01.99
PS C:\Users\eoeo2\Desktop\RageMP\Source\DiscordBot>
arion
arionโ€ข8mo ago
try going to C:\Users\eoeo2\Desktop\RageMP\Output\Debug\netcoreapp3.1\linux-x64\ and see if your binary is there now if it is, move that into the previous directory
PolishDywan
PolishDywanโ€ข8mo ago
Robi jebany
arion
arionโ€ข8mo ago
what?
PolishDywan
PolishDywanโ€ข8mo ago
Shiii, nothing xD Sorry.
TIME: 2023-11-09T02:12:53
MOST RECENT COMMAND: startdiscordbot
MOST RECENT QUERY #10: SELECT id, item_id, item_value, current_socket, parent, parent_type, stack_size FROM `inventories` WHERE parent_type=1 AND parent=2557;
MOST RECENT QUERY #9: SELECT faction_id, rank_index, manager FROM `faction_memberships` WHERE character_id=2557;
MOST RECENT QUERY #8: SELECT * FROM `keybinds` WHERE account=1 AND ((character_id = -1 AND bind_type=1) OR (character_id = 2557 AND bind_type=0));
MOST RECENT QUERY #7: UPDATE `properties` SET `entrance_x`=-188.65851, `entrance_y`=6353.191, `entrance_z`=30.425106, `exit_x`=1060.3695, `exit_y`=-1165.416, `exit_z`=2.16719, `state`=2, `buy_price`=69, `rent_price`=0, `owner`=2557, `renter`=-1, `locked`=False, `owner_type`=0, `renter_type`=0, `name`='Kutas', `entrance_rot`=-10.15813, `exit_rot`=0, `entrance_dimension`=0, `interior_id`=69, `payments_made`=0, `payments_missed`=0, `payments_remaining`=0, `entrance_type`=0, `credit_amount`=0, `last_used`=1699495970, `scripted_blip`=True, `is_token_purchase`=False, `xp`=0, `last_mowed_at`=0 WHERE id=1946;
MOST RECENT QUERY #6: SELECT account_id FROM `game_accounts` WHERE app_state=2;
MOST RECENT QUERY #5: SELECT id, account_id, title, click_event, body, UNIX_TIMESTAMP(created_at) as created_at FROM `notifications` WHERE account_id=1;
MOST RECENT QUERY #4: UPDATE `inventories` SET `item_value`='{\"value\":-1.0,\"duty\":false,\"is_legal\":true,\"semi_auto\":true}', `stack_size`=66 WHERE id=116890 LIMIT 1;;
MOST RECENT QUERY #3: UPDATE `inventories` SET `item_value`='{\"value\":-1.0,\"duty\":false,\"is_legal\":true,\"semi_auto\":true}', `stack_size`=66 WHERE id=116890 LIMIT 1;;
MOST RECENT QUERY #2: UPDATE `inventories` SET `item_value`='{\"value\":-1.0,\"duty\":false,\"is_legal\":true,\"semi_auto\":true}', `stack_size`=66 WHERE id=116890 LIMIT 1;;
MOST RECENT QUERY #1: UPDATE `inventories` SET `item_value`='{\"value\":-1.0,\"duty\":false,\"is_legal\":true
t
TIME: 2023-11-09T02:12:53
MOST RECENT COMMAND: startdiscordbot
MOST RECENT QUERY #10: SELECT id, item_id, item_value, current_socket, parent, parent_type, stack_size FROM `inventories` WHERE parent_type=1 AND parent=2557;
MOST RECENT QUERY #9: SELECT faction_id, rank_index, manager FROM `faction_memberships` WHERE character_id=2557;
MOST RECENT QUERY #8: SELECT * FROM `keybinds` WHERE account=1 AND ((character_id = -1 AND bind_type=1) OR (character_id = 2557 AND bind_type=0));
MOST RECENT QUERY #7: UPDATE `properties` SET `entrance_x`=-188.65851, `entrance_y`=6353.191, `entrance_z`=30.425106, `exit_x`=1060.3695, `exit_y`=-1165.416, `exit_z`=2.16719, `state`=2, `buy_price`=69, `rent_price`=0, `owner`=2557, `renter`=-1, `locked`=False, `owner_type`=0, `renter_type`=0, `name`='Kutas', `entrance_rot`=-10.15813, `exit_rot`=0, `entrance_dimension`=0, `interior_id`=69, `payments_made`=0, `payments_missed`=0, `payments_remaining`=0, `entrance_type`=0, `credit_amount`=0, `last_used`=1699495970, `scripted_blip`=True, `is_token_purchase`=False, `xp`=0, `last_mowed_at`=0 WHERE id=1946;
MOST RECENT QUERY #6: SELECT account_id FROM `game_accounts` WHERE app_state=2;
MOST RECENT QUERY #5: SELECT id, account_id, title, click_event, body, UNIX_TIMESTAMP(created_at) as created_at FROM `notifications` WHERE account_id=1;
MOST RECENT QUERY #4: UPDATE `inventories` SET `item_value`='{\"value\":-1.0,\"duty\":false,\"is_legal\":true,\"semi_auto\":true}', `stack_size`=66 WHERE id=116890 LIMIT 1;;
MOST RECENT QUERY #3: UPDATE `inventories` SET `item_value`='{\"value\":-1.0,\"duty\":false,\"is_legal\":true,\"semi_auto\":true}', `stack_size`=66 WHERE id=116890 LIMIT 1;;
MOST RECENT QUERY #2: UPDATE `inventories` SET `item_value`='{\"value\":-1.0,\"duty\":false,\"is_legal\":true,\"semi_auto\":true}', `stack_size`=66 WHERE id=116890 LIMIT 1;;
MOST RECENT QUERY #1: UPDATE `inventories` SET `item_value`='{\"value\":-1.0,\"duty\":false,\"is_legal\":true
t
I must set
/root/ragemp/netcoreapp3.1/linux-x64/
/root/ragemp/netcoreapp3.1/linux-x64/
directory?
arion
arionโ€ข8mo ago
or just move the contents of the folder. You should be able to figure out the rest, its not really C# advice anymore
PolishDywan
PolishDywanโ€ข8mo ago
@arion It's works! Thanks! ๐Ÿ™‚