Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why it #1564

Open
MakIcon opened this issue Sep 8, 2024 · 3 comments
Open

Why it #1564

MakIcon opened this issue Sep 8, 2024 · 3 comments

Comments

@MakIcon
Copy link

MakIcon commented Sep 8, 2024

why it dont work

func main() {
	token := 

	dg, err := discordgo.New(token)
	if err != nil {
		fmt.Println("Error creating Discord session:", err)
		return
	}

	defer func() {
		if r := recover(); r != nil {
			fmt.Println(r)
		}
	}()

	fmt.Println("Bot is now running. Press Ctrl+C to exit.")

	dg.Identify.Intents = discordgo.IntentsAll
	dg.AddHandler(messageCreate)
	dg.AddHandler(threadCreate)

	err = dg.Open()
	if err != nil {
		panic(err)
	}

	sc := make(chan os.Signal, 1)
	signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
	<-sc

	defer dg.Close()
}
func threadCreate(s *discordgo.Session, t *discordgo.ThreadCreate) {
	
	if t.ParentID == "1174286575878815855" {

		// Отправляем сообщение в новую ветку
		_, err := s.ChannelMessageSend(t.ID, "Привет! Я Модератор!")
		if err != nil {
			fmt.Println("Не удалось отправить сообщение в ветку:", err)
		} else {
			fmt.Println("Сообщение успешно отправлено в новую ветку:", t.ID)
		}
	}
}
@glotchimo
Copy link

Without knowing what your issue is, it's hard to say, but one thing that sticks out (non-breaking, just bad practice) is the fact that your deferral of session closure (defer dg.Close()) happens after the blocking signal reception (<-sc).

Mind sharing an error or more details about what's not working?

@MakIcon
Copy link
Author

MakIcon commented Sep 12, 2024

Without knowing what your issue is, it's hard to say, but one thing that sticks out (non-breaking, just bad practice) is the fact that your deferral of session closure (defer dg.Close()) happens after the blocking signal reception (<-sc).

Mind sharing an error or more details about what's not working?

@MakIcon
Copy link
Author

MakIcon commented Sep 12, 2024

Without knowing what your issue is, it's hard to say, but one thing that sticks out (non-breaking, just bad practice) is the fact that your deferral of session closure (defer dg.Close()) happens after the blocking signal reception (<-sc).

Mind sharing an error or more details about what's not working?

The code is supposed to detect the creation of a branch in several channels, but it doesn’t do this, and instead of this, after creating a branch in the desired channel, if you write to this branch, then the script is triggered and prints what is needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants